MQTT define bugfix

Possilbe mDNS bugfix
Switched to DBG method instead of multiple ifdef in httpd
pull/72/head
Benjamin Runnels 9 years ago
parent cb75396552
commit ed9b11186c
  1. 13
      WINDOWS.md
  2. 4
      esp-link.vcxproj
  3. 15
      esp-link/cgimqtt.c
  4. 2
      esp-link/cgimqtt.h
  5. 5
      esp-link/cgiwifi.c
  6. 61
      httpd/httpd.c

@ -0,0 +1,13 @@
* Install [SourceTree](https://www.sourcetreeapp.com) and check CLI git or other git distribution to do git from CLI
* Install and latest Java
* Install Python 2.7 to C:\Python27
* Install link shell extension from [here](http://schinagl.priv.at/nt/hardlinkshellext/linkshellextension.html)
* Download and install the [Windows Unofficial Development Kit for Espressif ESP8266](http://programs74.ru/get.php?file=EspressifESP8266DevKit) to c:\espressif
* Create a symbolic link for java/bin and git/bin directories under C:\espressif\git-bin and C:\espressif\java-bin. You have to do it like that because make doesn't like the full path with program files(x86). You can see all the expected paths in the [espmake.cmd](https://github.com/jeelabs/esp-link/blob/master/espmake.cmd)
* [Download](http://sourceforge.net/projects/mingw/files/Installer/) and install MinGW. Run mingw-get-setup.exe, the installation process to select without GUI, ie uncheck "... also install support for the graphical user interface".
* [Download](http://programs74.ru/get.php?file=EspressifESP8266DevKitAddon) the scripts to automate the installation of additional modules for MinGW.
* Run install-mingw-package.bat. This will establish the basic modules for MinGW. Installation should proceed without error.
* Checkout esp-link under C:\espressif\esp-link
* espmake.cmd "make all wiflash"
* new flash over serial then is espmake.cmd "make all flash"
* if you want to program with serial but not loose your config each time espmake.cmd "make all baseflash"

@ -16,6 +16,7 @@
<ClCompile Include="esp-link\cgi.c" />
<ClCompile Include="esp-link\cgiflash.c" />
<ClCompile Include="esp-link\cgimqtt.c" />
<ClCompile Include="esp-link\cgioptiboot.c" />
<ClCompile Include="esp-link\cgipins.c" />
<ClCompile Include="esp-link\cgitcp.c" />
<ClCompile Include="esp-link\cgiwifi.c" />
@ -50,6 +51,7 @@
<ClInclude Include="esp-link\cgi.h" />
<ClInclude Include="esp-link\cgiflash.h" />
<ClInclude Include="esp-link\cgimqtt.h" />
<ClInclude Include="esp-link\cgioptiboot.h" />
<ClInclude Include="esp-link\cgipins.h" />
<ClInclude Include="esp-link\cgitcp.h" />
<ClInclude Include="esp-link\cgiwifi.h" />
@ -57,6 +59,7 @@
<ClInclude Include="esp-link\log.h" />
<ClInclude Include="esp-link\mqtt_client.h" />
<ClInclude Include="esp-link\status.h" />
<ClInclude Include="esp-link\stk500.h" />
<ClInclude Include="espfs\espfs.h" />
<ClInclude Include="espfs\espfsformat.h" />
<ClInclude Include="espfs\mkespfsimage\mman-win32\mman.h" />
@ -81,6 +84,7 @@
<ClInclude Include="serial\uart.h" />
</ItemGroup>
<ItemGroup>
<None Include="avrflash" />
<None Include="BOARDS.md" />
<None Include="espmake.cmd" />
<None Include="FLASH.md" />

@ -1,5 +1,14 @@
// Copyright 2015 by Thorsten von Eicken, see LICENSE.txt
#ifdef MQTT
static char *mqtt_states[] = {
"disconnected", "reconnecting", "connecting", "connected", "disabled"
};
#if !defined(MQTT)
char *mqttState(void) {
return mqtt_states[4];
}
#else
#include <esp8266.h>
#include "cgi.h"
#include "config.h"
@ -7,10 +16,6 @@
#include "mqtt_client.h"
#include "cgimqtt.h"
static char *mqtt_states[] = {
"disconnected", "reconnecting", "connecting", "connected",
};
char *mqttState(void) {
return mqtt_states[mqttClient.connState];
}

@ -1,10 +1,10 @@
char *mqttState(void);
#ifdef MQTT
#ifndef CGIMQTT_H
#define CGIMQTT_H
#include "httpd.h"
int cgiMqtt(HttpdConnData *connData);
char *mqttState(void);
#endif // CGIMQTT_H
#endif // MQTT

@ -121,10 +121,11 @@ static ICACHE_FLASH_ATTR
void wifiStartMDNS(struct ip_addr ip) {
if (!mdns_started) {
os_memset(&mdns_info, 0, sizeof(struct mdns_info));
mdns_info.host_name = flashConfig.hostname;
mdns_info.host_name = flashConfig.hostname,
mdns_info.server_name = "http", // service name
mdns_info.server_port = 80, // service port
mdns_info.ipAddr = ip.addr,
mdns_info.ipAddr = ip.addr,
mdns_info.txt_data[0] = (char *) "version = now",
espconn_mdns_init(&mdns_info);
mdns_started = true;
}

@ -17,7 +17,11 @@ Esp8266 http server - core routines
#include <esp8266.h>
#include "httpd.h"
//#define HTTPD_DBG
#ifdef HTTPD_DBG
#define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#else
#define DBG(format, ...) do { } while(0)
#endif
//Max length of request head
@ -97,7 +101,7 @@ static void debugConn(void *arg, char *what) {
os_sprintf(connStr, "%d.%d.%d.%d:%d ",
tcp->remote_ip[0], tcp->remote_ip[1], tcp->remote_ip[2], tcp->remote_ip[3],
tcp->remote_port);
os_printf("%s %s\n", connStr, what);
DBG("%s %s\n", connStr, what);
#else
connStr[0] = 0;
#endif
@ -108,20 +112,18 @@ static void ICACHE_FLASH_ATTR httpdRetireConn(HttpdConnData *conn) {
if (conn->conn && conn->conn->reverse == conn)
conn->conn->reverse = NULL; // break reverse link
#ifdef HTTPD_DBG
// log information about the request we handled
uint32 dt = conn->startTime;
if (dt > 0) dt = (system_get_time() - dt) / 1000;
if (conn->conn && conn->url)
#if 0
os_printf("HTTP %s %s from %s -> %d in %ums, heap=%ld\n",
DBG("HTTP %s %s from %s -> %d in %ums, heap=%ld\n",
conn->requestType == HTTPD_METHOD_GET ? "GET" : "POST", conn->url, conn->priv->from,
conn->priv->code, dt, (unsigned long)system_get_free_heap_size());
#else
os_printf("HTTP %s %s: %d, %ums, h=%ld\n",
DBG("HTTP %s %s: %d, %ums, h=%ld\n",
conn->requestType == HTTPD_METHOD_GET ? "GET" : "POST", conn->url,
conn->priv->code, dt, (unsigned long)system_get_free_heap_size());
#endif
#endif
conn->conn = NULL; // don't try to send anything, the SDK crashes...
@ -276,10 +278,8 @@ int ICACHE_FLASH_ATTR cgiRedirect(HttpdConnData *connData) {
int ICACHE_FLASH_ATTR httpdSend(HttpdConnData *conn, const char *data, int len) {
if (len<0) len = strlen(data);
if (conn->priv->sendBuffLen + len>MAX_SENDBUFF_LEN) {
#ifdef HTTPD_DBG
os_printf("%sERROR! httpdSend full (%d of %d)\n",
DBG("%sERROR! httpdSend full (%d of %d)\n",
connStr, conn->priv->sendBuffLen, MAX_SENDBUFF_LEN);
#endif
return 0;
}
os_memcpy(conn->priv->sendBuff + conn->priv->sendBuffLen, data, len);
@ -292,10 +292,8 @@ static void ICACHE_FLASH_ATTR xmitSendBuff(HttpdConnData *conn) {
if (conn->priv->sendBuffLen != 0) {
sint8 status = espconn_sent(conn->conn, (uint8_t*)conn->priv->sendBuff, conn->priv->sendBuffLen);
if (status != 0) {
#ifdef HTTPD_DBG
os_printf("%sERROR! espconn_sent returned %d, trying to send %d to %s\n",
DBG("%sERROR! espconn_sent returned %d, trying to send %d to %s\n",
connStr, status, conn->priv->sendBuffLen, conn->url);
#endif
}
conn->priv->sendBuffLen = 0;
}
@ -323,9 +321,7 @@ static void ICACHE_FLASH_ATTR httpdSentCb(void *arg) {
conn->cgi = NULL; //mark for destruction.
}
if (r == HTTPD_CGI_NOTFOUND || r == HTTPD_CGI_AUTHENTICATED) {
#ifdef HTTPD_DBG
os_printf("%sERROR! Bad CGI code %d\n", connStr, r);
#endif
DBG("%sERROR! Bad CGI code %d\n", connStr, r);
conn->cgi = NULL; //mark for destruction.
}
xmitSendBuff(conn);
@ -342,9 +338,7 @@ static void ICACHE_FLASH_ATTR httpdProcessRequest(HttpdConnData *conn) {
int r;
int i = 0;
if (conn->url == NULL) {
#ifdef HTTPD_DBG
os_printf("%sWtF? url = NULL\n", connStr);
#endif
DBG("%sWtF? url = NULL\n", connStr);
return; //Shouldn't happen
}
//See if we can find a CGI that's happy to handle the request.
@ -370,9 +364,7 @@ static void ICACHE_FLASH_ATTR httpdProcessRequest(HttpdConnData *conn) {
if (builtInUrls[i].url == NULL) {
//Drat, we're at the end of the URL table. This usually shouldn't happen. Well, just
//generate a built-in 404 to handle this.
#ifdef HTTPD_DBG
os_printf("%s%s not found. 404!\n", connStr, conn->url);
#endif
DBG("%s%s not found. 404!\n", connStr, conn->url);
httpdSend(conn, httpNotFoundHeader, -1);
xmitSendBuff(conn);
conn->cgi = NULL; //mark for destruction.
@ -436,19 +428,15 @@ static void ICACHE_FLASH_ATTR httpdParseHeader(char *h, HttpdConnData *conn) {
*e = 0; //terminate url part
// Count number of open connections
#ifdef HTTPD_DBG
//esp_tcp *tcp = conn->conn->proto.tcp;
//os_printf("%sHTTP %s %s from %s\n", connStr,
//DBG("%sHTTP %s %s from %s\n", connStr,
// conn->requestType == HTTPD_METHOD_GET ? "GET" : "POST", conn->url, conn->priv->from);
#endif
//Parse out the URL part before the GET parameters.
conn->getArgs = (char*)os_strstr(conn->url, "?");
if (conn->getArgs != 0) {
*conn->getArgs = 0;
conn->getArgs++;
#ifdef HTTPD_DBG
//os_printf("%sargs = %s\n", connStr, conn->getArgs);
#endif
//DBG("%sargs = %s\n", connStr, conn->getArgs);
}
else {
conn->getArgs = NULL;
@ -470,7 +458,7 @@ static void ICACHE_FLASH_ATTR httpdParseHeader(char *h, HttpdConnData *conn) {
else {
conn->post->buffSize = conn->post->len;
}
//os_printf("Mallocced buffer for %d + 1 bytes of post data.\n", conn->post->buffSize);
//DBG("Mallocced buffer for %d + 1 bytes of post data.\n", conn->post->buffSize);
conn->post->buff = (char*)os_malloc(conn->post->buffSize + 1);
conn->post->buffLen = 0;
}
@ -482,7 +470,7 @@ static void ICACHE_FLASH_ATTR httpdParseHeader(char *h, HttpdConnData *conn) {
conn->post->multipartBoundary = b + 7; // move the pointer 2 chars before boundary then fill them with dashes
conn->post->multipartBoundary[0] = '-';
conn->post->multipartBoundary[1] = '-';
//os_printf("boundary = %s\n", conn->post->multipartBoundary);
//DBG("boundary = %s\n", conn->post->multipartBoundary);
}
}
}
@ -562,10 +550,7 @@ static void ICACHE_FLASH_ATTR httpdReconCb(void *arg, sint8 err) {
struct espconn* pCon = (struct espconn *)arg;
HttpdConnData *conn = (HttpdConnData *)pCon->reverse;
if (conn == NULL) return; // aborted connection
#ifdef HTTPD_DBG
os_printf("%s***** reset, err=%d\n", connStr, err);
#endif
DBG("%s***** reset, err=%d\n", connStr, err);
httpdRetireConn(conn);
}
@ -577,7 +562,7 @@ static void ICACHE_FLASH_ATTR httpdConnectCb(void *arg) {
// Find empty conndata in pool
int i;
for (i = 0; i<MAX_CONN; i++) if (connData[i].conn == NULL) break;
//os_printf("Con req, conn=%p, pool slot %d\n", conn, i);
//DBG("Con req, conn=%p, pool slot %d\n", conn, i);
if (i == MAX_CONN) {
os_printf("%sHTTP: conn pool overflow!\n", connStr);
espconn_disconnect(conn);
@ -587,9 +572,7 @@ static void ICACHE_FLASH_ATTR httpdConnectCb(void *arg) {
#if 0
int num = 0;
for (int j = 0; j<MAX_CONN; j++) if (connData[j].conn != NULL) num++;
#ifdef HTTPD_DBG
os_printf("%sConnect (%d open)\n", connStr, num + 1);
#endif
DBG("%sConnect (%d open)\n", connStr, num + 1);
#endif
connData[i].priv = &connPrivData[i];
@ -627,9 +610,7 @@ void ICACHE_FLASH_ATTR httpdInit(HttpdBuiltInUrl *fixedUrls, int port) {
httpdTcp.local_port = port;
httpdConn.proto.tcp = &httpdTcp;
builtInUrls = fixedUrls;
#ifdef HTTPD_DBG
os_printf("Httpd init, conn=%p\n", &httpdConn);
#endif
DBG("Httpd init, conn=%p\n", &httpdConn);
espconn_regist_connectcb(&httpdConn, httpdConnectCb);
espconn_accept(&httpdConn);
espconn_tcp_set_max_con_allow(&httpdConn, MAX_CONN);

Loading…
Cancel
Save