Updates for SDK 1.5

pull/72/head
Benjamin Runnels 9 years ago
parent 5935a30f03
commit 26339962bf
  1. 8
      Makefile
  2. 55
      cmd/cmd.c
  3. 22
      cmd/handlers.c
  4. 2
      esp-link.vcxproj
  5. 23
      esp-link/cgiwifi.c
  6. 29
      esp-link/mdns.c
  7. 2
      include/user_config.h

@ -21,7 +21,7 @@ XTENSA_TOOLS_ROOT ?= $(abspath ../esp-open-sdk/xtensa-lx106-elf/bin)/
# Base directory of the ESP8266 SDK package, absolute
# Typically you'll download from Espressif's BBS, http://bbs.espressif.com/viewforum.php?f=5
SDK_BASE ?= $(abspath ../esp_iot_sdk_v1.4.0)
SDK_BASE ?= $(abspath ../esp_iot_sdk_v1.5.0)
# Esptool.py path and port, only used for 1-time serial flashing
# Typically you'll use https://github.com/themadinventor/esptool
@ -185,7 +185,7 @@ MODULES += $(foreach sdir,$(LIBRARIES_DIR),$(wildcard $(sdir)/*))
EXTRA_INCDIR = include .
# libraries used in this project, mainly provided by the SDK
LIBS = c gcc hal phy pp net80211 wpa main lwip
LIBS = c gcc hal phy pp net80211 wpa main lwip crypto
# compiler flags using during compilation of source files
CFLAGS += -Os -ggdb -std=c99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions \
@ -300,7 +300,7 @@ $(FW_BASE)/user1.bin: $(USER1_OUT) $(FW_BASE)
$(Q) $(OBJCP) --only-section .rodata -O binary $(USER1_OUT) eagle.app.v6.rodata.bin
$(Q) $(OBJCP) --only-section .irom0.text -O binary $(USER1_OUT) eagle.app.v6.irom0text.bin
ls -ls eagle*bin
$(Q) COMPILE=gcc PATH=$(XTENSA_TOOLS_ROOT):$(PATH) python $(APPGEN_TOOL) $(USER1_OUT) 2 $(ESP_FLASH_MODE) $(ESP_FLASH_FREQ_DIV) $(ESP_SPI_SIZE)
$(Q) COMPILE=gcc PATH=$(XTENSA_TOOLS_ROOT):$(PATH) python $(APPGEN_TOOL) $(USER1_OUT) 2 $(ESP_FLASH_MODE) $(ESP_FLASH_FREQ_DIV) $(ESP_SPI_SIZE) 0
$(Q) rm -f eagle.app.v6.*.bin
$(Q) mv eagle.app.flash.bin $@
@echo "** user1.bin uses $$(stat -c '%s' $@) bytes of" $(ESP_FLASH_MAX) "available"
@ -311,7 +311,7 @@ $(FW_BASE)/user2.bin: $(USER2_OUT) $(FW_BASE)
$(Q) $(OBJCP) --only-section .data -O binary $(USER2_OUT) eagle.app.v6.data.bin
$(Q) $(OBJCP) --only-section .rodata -O binary $(USER2_OUT) eagle.app.v6.rodata.bin
$(Q) $(OBJCP) --only-section .irom0.text -O binary $(USER2_OUT) eagle.app.v6.irom0text.bin
$(Q) COMPILE=gcc PATH=$(XTENSA_TOOLS_ROOT):$(PATH) python $(APPGEN_TOOL) $(USER2_OUT) 2 $(ESP_FLASH_MODE) $(ESP_FLASH_FREQ_DIV) $(ESP_SPI_SIZE)
$(Q) COMPILE=gcc PATH=$(XTENSA_TOOLS_ROOT):$(PATH) python $(APPGEN_TOOL) $(USER2_OUT) 2 $(ESP_FLASH_MODE) $(ESP_FLASH_FREQ_DIV) $(ESP_SPI_SIZE) 0
$(Q) rm -f eagle.app.v6.*.bin
$(Q) mv eagle.app.flash.bin $@
$(Q) if [ $$(stat -c '%s' $@) -gt $$(( $(ESP_FLASH_MAX) )) ]; then echo "$@ too big!"; false; fi

@ -7,8 +7,22 @@
#include "crc16.h"
#include "uart.h"
#ifdef CMD_DBG
#define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#else
#define DBG(format, ...) do { } while(0)
#endif
extern const CmdList commands[];
static const char *cmd_names[] = {
"NULL", "RESET", "IS_READY", "WIFI_CONNECT",
"MQTT_SETUP", "MQTT_CONNECT", "MQTT_DISCONNECT",
"MQTT_PUBLISH", "MQTT_SUBSCRIBE", "MQTT_LWT", "MQTT_EVENTS",
"REST_SETUP", "REST_REQUEST", "REST_SETHEADER", "REST_EVENTS",
"CB_ADD", "CB_EVENTS",
};
//===== ESP -> Serial responses
static void ICACHE_FLASH_ATTR
@ -82,39 +96,25 @@ CMD_Exec(const CmdList *scp, CmdPacket *packet) {
// Iterate through the command table and call the appropriate function
while (scp->sc_function != NULL) {
if(scp->sc_name == packet->cmd) {
//os_printf("CMD: Dispatching cmd=%d\n", packet->cmd);
DBG("CMD_Exec: Dispatching cmd=%s\n", cmd_names[packet->cmd]);
// call command function
uint32_t ret = scp->sc_function(packet);
// if requestor asked for a response, send it
if (packet->_return){
#ifdef CMD_DBG
os_printf("CMD: Response: 0x%lx, cmd: %d\r\n", ret, packet->cmd);
#endif
DBG("CMD_Exec: Response: 0x%lx, cmd: %d\r\n", ret, packet->cmd);
crc = CMD_ResponseStart(packet->cmd, 0, ret, 0);
CMD_ResponseEnd(crc);
} else {
#ifdef CMD_DBG
os_printf("CMD: no response (%lu)\n", packet->_return);
#endif
DBG("CMD_Exec: no response (%lu)\n", packet->_return);
}
return ret;
}
scp++;
}
#ifdef CMD_DBG
os_printf("CMD: cmd=%d not found\n", packet->cmd);
#endif
DBG("CMD_Exec: cmd=%d not found\n", packet->cmd);
return 0;
}
char *cmd_names[] = {
"NULL", "RESET", "IS_READY", "WIFI_CONNECT",
"MQTT_SETUP", "MQTT_CONNECT", "MQTT_DISCONNECT",
"MQTT_PUBLISH", "MQTT_SUBSCRIBE", "MQTT_LWT", "MQTT_EVENTS",
"REST_SETUP", "REST_REQUEST", "REST_SETHEADER", "REST_EVENTS",
"CB_ADD", "CB_EVENTS",
};
// Parse a packet and print info about it
void ICACHE_FLASH_ATTR
CMD_parse_packet(uint8_t *buf, short len) {
@ -125,18 +125,21 @@ CMD_parse_packet(uint8_t *buf, short len) {
CmdPacket *packet = (CmdPacket*)buf;
uint8_t *data_ptr = (uint8_t*)&packet->args;
uint8_t *data_limit = data_ptr+len;
#ifdef CMD_DBG
uint16_t argn = 0;
os_printf("CMD: cmd=%d(%s) argc=%d cb=%p ret=%lu\n",
packet->cmd, cmd_names[packet->cmd], packet->argc, (void *)packet->callback, packet->_return);
#endif
DBG("CMD_parse_packet: cmd=%d(%s) argc=%d cb=%p ret=%lu\n",
packet->cmd,
cmd_names[packet->cmd],
packet->argc,
(void *)packet->callback,
packet->_return
);
#if 0
// print out arguments
// print out arguments
uint16_t argc = packet->argc;
while (data_ptr+2 < data_limit && argc--) {
short l = *(uint16_t*)data_ptr;
os_printf("CMD: arg[%d] len=%d:", argn++, l);
os_printf("CMD_parse_packet: arg[%d] len=%d:", argn++, l);
data_ptr += 2;
while (data_ptr < data_limit && l--) {
os_printf(" %02X", *data_ptr++);
@ -148,9 +151,7 @@ CMD_parse_packet(uint8_t *buf, short len) {
if (data_ptr <= data_limit) {
CMD_Exec(commands, packet);
} else {
#ifdef CMD_DBG
os_printf("CMD: packet length overrun, parsing arg %d\n", argn-1);
#endif
DBG("CMD_parse_packet: packet length overrun, parsing arg %d\n", argn - 1);
}
}

@ -12,6 +12,12 @@
#include <rest.h>
#endif
#ifdef CMD_DBG
#define DBG(format, ...) os_printf(format, ## __VA_ARGS__)
#else
#define DBG(format, ...) do { } while(0)
#endif
static uint32_t CMD_Null(CmdPacket *cmd);
static uint32_t CMD_IsReady(CmdPacket *cmd);
static uint32_t CMD_Reset(CmdPacket *cmd);
@ -81,9 +87,7 @@ CMD_AddCb(char* name, uint32_t cb) {
os_strncpy(callbacks[i].name, name, sizeof(callbacks[i].name));
callbacks[i].name[CMD_CBNLEN-1] = 0; // strncpy doesn't null terminate
callbacks[i].callback = cb;
#ifdef CMD_DBG
os_printf("CMD_AddCb: cb %s added at index %d\n", callbacks[i].name, i);
#endif
DBG("CMD_AddCb: cb %s added at index %d\n", callbacks[i].name, i);
return 1;
}
}
@ -97,9 +101,7 @@ CMD_GetCbByName(char* name) {
// (void *)callbacks[i].callback);
// if callback doesn't exist or it's null
if (os_strncmp(callbacks[i].name, name, CMD_CBNLEN) == 0) {
#ifdef CMD_DBG
os_printf("CMD_GetCbByName: cb %s found at index %d\n", name, i);
#endif
DBG("CMD_GetCbByName: cb %s found at index %d\n", name, i);
return &callbacks[i];
}
}
@ -111,9 +113,7 @@ CMD_GetCbByName(char* name) {
static void ICACHE_FLASH_ATTR
CMD_WifiCb(uint8_t wifiStatus) {
if (wifiStatus != lastWifiStatus){
#ifdef CMD_DBG
os_printf("CMD_WifiCb: wifiStatus=%d\n", wifiStatus);
#endif
DBG("CMD_WifiCb: wifiStatus=%d\n", wifiStatus);
lastWifiStatus = wifiStatus;
cmdCallback *wifiCb = CMD_GetCbByName("wifiCb");
if ((uint32_t)wifiCb->callback != -1) {
@ -160,9 +160,7 @@ CMD_AddCallback(CmdPacket *cmd) {
if (len > 15) return 0; // max size of name is 15 characters
if (CMD_PopArg(&req, (uint8_t *)name, len)) return 0;
name[len] = 0;
#ifdef CMD_DBG
os_printf("CMD_AddCallback: name=%s\n", name);
#endif
DBG("CMD_AddCallback: name=%s\n", name);
return CMD_AddCb(name, (uint32_t)cmd->callback); // save the sensor callback
}

@ -132,7 +132,7 @@
<PropertyGroup>
<NMakeOutput />
<NMakePreprocessorDefinitions>__ets__;_STDINT_H;ICACHE_FLASH;__MINGW32__;__WIN32__;MQTT</NMakePreprocessorDefinitions>
<NMakeIncludeSearchPath>.\rest;.\esp-link;.\mqtt;.\cmd;.\serial;.\user;.\espfs;.\httpd;.\include;..\esp_iot_sdk_v1.4.0\include;..\xtensa-lx106-elf\xtensa-lx106-elf\include;c:\tools\mingw64\x86_64-w64-mingw32\include;c:\tools\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.3\include</NMakeIncludeSearchPath>
<NMakeIncludeSearchPath>.\rest;.\esp-link;.\mqtt;.\cmd;.\serial;.\user;.\espfs;.\httpd;.\include;..\esp_iot_sdk_v1.5.0\include;..\xtensa-lx106-elf\xtensa-lx106-elf\include;c:\tools\mingw64\x86_64-w64-mingw32\include;c:\tools\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.3\include</NMakeIncludeSearchPath>
<ExecutablePath />
<ReferencePath />
<LibraryPath />

@ -115,25 +115,18 @@ wifiAddStateChangeCb(WifiStateChangeCb cb) {
}
static bool mdns_started = false;
//static struct mdns_info mdns_info;
// cannot allocate the info struct on the stack, it crashes!
//
static ICACHE_FLASH_ATTR
void wifiStartMDNS(struct ip_addr ip) {
if (!mdns_started) {
// struct mdns_info *ard_mdns_info = (struct mdns_info *)os_zalloc(sizeof(struct mdns_info));
// ard_mdns_info->host_name = flashConfig.hostname;
// ard_mdns_info->server_name = "arduino"; // service name
// ard_mdns_info->server_port = 2323; // service port
// ard_mdns_info->ipAddr = ip.addr;
// ard_mdns_info->txt_data[0] = (char *) "version = now";
// espconn_mdns_init(ard_mdns_info);
// espconn_mdns_server_register();
mdns_init(60, 3600);
mdns_addhost(flashConfig.hostname, &ip);
//mdns_addhost("arduino", &ip);
mdns_started = true;
struct mdns_info *mdns_info = (struct mdns_info *)os_zalloc(sizeof(struct mdns_info));
mdns_info->host_name = flashConfig.hostname;
mdns_info->server_name = "arduino"; // service name
mdns_info->server_port = 80; // service port
mdns_info->ipAddr = ip.addr;
espconn_mdns_init(mdns_info);
mdns_started = true;
}
}

@ -38,6 +38,7 @@ struct ip_addr mdns_multicast;
struct ip_addr ipaddr_any;
#ifdef MDNS_DBG
void ICACHE_FLASH_ATTR hexdump(char *desc, void *addr, int len) {
int i;
unsigned char buff[17];
@ -118,8 +119,7 @@ unsigned ICACHE_FLASH_ATTR char * encodeResp(struct ip_addr * addr, char *name,
*p++ = 0; *p++ = 4; // length (of ip)
memcpy(p, addr, 4);
memcpy(p, addr, 4);
return data;
}
@ -156,7 +156,7 @@ void ICACHE_FLASH_ATTR sendOne(struct _host *h)
mdns_conn.proto.udp->remote_port = 5353;
mdns_conn.proto.udp->local_port = 5353;
#ifdef MDNS_DBG
hexdump("sending", h->mdns, h->len);
// hexdump("sending", h->mdns, h->len);
#endif
espconn_sent(&mdns_conn, h->mdns, h->len);
@ -184,7 +184,7 @@ void ICACHE_FLASH_ATTR decodeQuery(unsigned char *data)
int qtype = p[0] * 256 + p[1];
int qclass = p[2] * 256 + p[3];
p += 4;
DBG("decoded name %s qtype=%d qclass=%d\n", name, qtype, qclass);
// DBG("decoded name %s qtype=%d qclass=%d\n", name, qtype, qclass);
if (qtype == 1 && (qclass & 0x7fff) == 1)
{
@ -194,7 +194,7 @@ void ICACHE_FLASH_ATTR decodeQuery(unsigned char *data)
{
if (h->hostname && strcmp(name, h->hostname) == 0)
{
DBG("its %s!\n", h->hostname);
// DBG("its %s!\n", h->hostname);
sendOne(h);
}
}
@ -211,7 +211,7 @@ static void ICACHE_FLASH_ATTR broadcast(void *arg)
int i;
for (h = hosts, i = 0; i < nhosts; i++, h++)
{
DBG("broadcast for %s\n", h->hostname);
// DBG("broadcast for %s\n", h->hostname);
sendOne(h);
}
}
@ -220,12 +220,12 @@ static void ICACHE_FLASH_ATTR mdns_udp_recv(void *arg, char *pusrdata, unsigned
unsigned char *data = (unsigned char *)pusrdata;
DBG("remote port=%d remoteip=%d.%d.%d.%d\n", mdns_conn.proto.udp->remote_port,
mdns_conn.proto.udp->remote_ip[0],
mdns_conn.proto.udp->remote_ip[1],
mdns_conn.proto.udp->remote_ip[2],
mdns_conn.proto.udp->remote_ip[3]
);
// DBG("remote port=%d remoteip=%d.%d.%d.%d\n", mdns_conn.proto.udp->remote_port,
// mdns_conn.proto.udp->remote_ip[0],
// mdns_conn.proto.udp->remote_ip[1],
// mdns_conn.proto.udp->remote_ip[2],
// mdns_conn.proto.udp->remote_ip[3]
// );
#ifdef MDNS_DBG
// hexdump("rec mNDS:", data, length);
#endif
@ -252,6 +252,7 @@ int ICACHE_FLASH_ATTR mdns_addhost(char *hn, struct ip_addr* ip)
os_strcpy(h->hostname, hn);
h->ip.addr = ip->addr;
h->mdns = encodeResp(ip, hn, &(h->len));
// DBG("resp len: %d\n", ets_strlen(h->mdns));
#ifdef MDNS_DBG
hexdump("addhost", hosts, sizeof(hosts));
#endif
@ -270,8 +271,6 @@ int ICACHE_FLASH_ATTR mdns_delhost(char *hn, struct ip_addr* ip)
{
if (h->hostname) os_free(h->hostname);
if (h->mdns) os_free(h->mdns);
h->hostname = NULL;
h->mdns = NULL;
h->ip.addr = 0;
}
}
@ -326,8 +325,6 @@ int ICACHE_FLASH_ATTR mdns_stop()
{
if (h->hostname) os_free(h->hostname);
if (h->mdns) os_free(h->mdns);
h->hostname = NULL;
h->mdns = NULL;
h->ip.addr = 0;
}
nhosts = 0;

@ -19,7 +19,7 @@
#define CONFIG_DBG
#define LOG_DBG
#define STATUS_DBG
#define HTTPD_DBG
#undef HTTPD_DBG
#define MQTT_DBG
#define MQTTCMD_DBG
#undef PKTBUF_DBG

Loading…
Cancel
Save