Skip to content

Commit

Permalink
converted some DBG macros; misc tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
tve committed Sep 13, 2015
1 parent 35c2eb6 commit f057a65
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 193 deletions.
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,6 @@ ifneq (,$(findstring rest,$(MODULES)))
CFLAGS += -DREST
endif

ifneq (,$(findstring tcpclient,$(MODULES)))
CFLAGS += -DTCPCLIENT
endif

# which modules (subdirectories) of the project to include in compiling
LIBRARIES_DIR = libraries
MODULES += espfs httpd user serial cmd esp-link
Expand Down
8 changes: 4 additions & 4 deletions esp-link/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ bool ICACHE_FLASH_ATTR configRestore(void) {
os_sprintf(chipIdStr, "%06x", system_get_chip_id());
os_memcpy(&flashConfig.mqtt_clientid, chipIdStr, os_strlen(chipIdStr));
#ifdef CHIP_IN_HOSTNAME
char hostname[16];
char hostname[16];
os_strcpy(hostname, "esp-link-");
os_strcat(hostname, chipIdStr);
os_memcpy(&flashConfig.hostname, hostname, os_strlen(hostname));
Expand All @@ -138,8 +138,8 @@ static int ICACHE_FLASH_ATTR selectPrimary(FlashFull *ff0, FlashFull *ff1) {
#ifdef CONFIG_DBG
os_printf("FLASH chk=0x%04x crc=0x%04x full_sz=%d sz=%d chip_sz=%d\n",
crc16_data((unsigned char*)ff0, sizeof(FlashFull), 0),
crc,
sizeof(FlashFull),
crc,
sizeof(FlashFull),
sizeof(FlashConfig),
getFlashSize());
#endif
Expand All @@ -164,7 +164,7 @@ const size_t ICACHE_FLASH_ATTR
getFlashSize() {
uint32_t id = spi_flash_get_id();
uint8_t mfgr_id = id & 0xff;
uint8_t type_id = (id >> 8) & 0xff; // not relevant for size calculation
//uint8_t type_id = (id >> 8) & 0xff; // not relevant for size calculation
uint8_t size_id = (id >> 16) & 0xff; // lucky for us, WinBond ID's their chips as a form that lets us calculate the size
if (mfgr_id != 0xEF) // 0xEF is WinBond; that's all we care about (for now)
return 0;
Expand Down
33 changes: 2 additions & 31 deletions esp-link/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,6 @@

//#define SHOW_HEAP_USE

//Function that tells the authentication system what users/passwords live on the system.
//This is disabled in the default build; if you want to try it, enable the authBasic line in
//the builtInUrls below.
//int myPassFn(HttpdConnData *connData, int no, char *user, int userLen, char *pass, int passLen) {
// if (no == 0) {
// os_strcpy(user, "admin");
// os_strcpy(pass, "s3cr3t");
// return 1;
//Add more users this way. Check against incrementing no for each user added.
// } else if (no==1) {
// os_strcpy(user, "user1");
// os_strcpy(pass, "something");
// return 1;
// }
// return 0;
//}


/*
This is the main url->function dispatching data struct.
In short, it's a struct with various URLs plus their handlers. The handlers can
Expand All @@ -66,23 +48,15 @@ HttpdBuiltInUrl builtInUrls[] = {
{ "/flash/next", cgiGetFirmwareNext, NULL },
{ "/flash/upload", cgiUploadFirmware, NULL },
{ "/flash/reboot", cgiRebootFirmware, NULL },
//{"/home.html", cgiEspFsHtml, NULL},
//{"/log.html", cgiEspFsHtml, NULL},
{ "/log/text", ajaxLog, NULL },
{ "/log/dbg", ajaxLogDbg, NULL },
//{"/console.html", cgiEspFsHtml, NULL},
{ "/console/reset", ajaxConsoleReset, NULL },
{ "/console/baud", ajaxConsoleBaud, NULL },
{ "/console/text", ajaxConsole, NULL },

//Routines to make the /wifi URL and everything beneath it work.

//Enable the line below to protect the WiFi configuration with an username/password combo.
// {"/wifi/*", authBasic, myPassFn},

{ "/wifi", cgiRedirect, "/wifi/wifi.html" },
{ "/wifi/", cgiRedirect, "/wifi/wifi.html" },
//{"/wifi/wifi.html", cgiEspFsHtml, NULL},
{ "/wifi/info", cgiWifiInfo, NULL },
{ "/wifi/scan", cgiWiFiScan, NULL },
{ "/wifi/connect", cgiWiFiConnect, NULL },
Expand Down Expand Up @@ -128,18 +102,15 @@ extern void mqtt_client_init(void);

// Main routine to initialize esp-link.
void user_init(void) {
uart_init(115200, 115200);
logInit(); // must come after init of uart
os_delay_us(10000L);
// get the flash config so we know how to init things
//configWipe(); // uncomment to reset the config for testing purposes
bool restoreOk = configRestore();
// init gpio pin registers
gpio_init();
gpio_output_set(0, 0, 0, (1<<15)); // some people tie it GND, gotta ensure it's disabled
// init UART
// uart_init(flashConfig.baud_rate, 115200);
// logInit(); // must come after init of uart
uart_init(flashConfig.baud_rate, 115200);
logInit(); // must come after init of uart
// say hello (leave some time to cause break in TX after boot loader's msg
os_delay_us(10000L);
os_printf("\n\n** %s\n", esp_link_version);
Expand Down
9 changes: 9 additions & 0 deletions esp-link/mqtt_client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef MQTT_CLIENT_H
#define MQTT_CLIENT_H

#include "mqtt.h"

extern MQTT_Client mqttClient;
void mqtt_client_init();

#endif
11 changes: 6 additions & 5 deletions include/user_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#define DEBUGIP

#define CMD_DBG
#define ESPFS_DBG
#define CGI_DBG
#undef ESPFS_DBG
#undef CGI_DBG
#define CGIFLASH_DBG
#define CGIMQTT_DBG
#define CGIPINS_DBG
Expand All @@ -20,17 +20,18 @@
#define HTTPD_DBG
#define MQTT_DBG
#define MQTTCMD_DBG
#define PKTBUF_DBG
#undef PKTBUF_DBG
#define REST_DBG
#define RESTCMD_DBG
#define SERBR_DBG
#define SERLED_DBG
#define SLIP_DBG
#define UART_DBG

#define CHIP_IN_HOSTNAME
// If defined, the default hostname for DHCP will include the chip ID to make it unique
#undef CHIP_IN_HOSTNAME

extern char* esp_link_version;
extern uint8_t UTILS_StrToIP(const char* str, void *ip);

#endif
#endif
18 changes: 10 additions & 8 deletions mqtt/mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,36 +162,36 @@ mqtt_tcpclient_recv(void* arg, char* pdata, unsigned short len) {

switch (msg_type) {
case MQTT_MSG_TYPE_CONNACK:
DBG_MQTT("MQTT: Connect successful\n");
//DBG_MQTT("MQTT: Connect successful\n");
// callbacks for internal and external clients
if (client->connectedCb) client->connectedCb((uint32_t*)client);
if (client->cmdConnectedCb) client->cmdConnectedCb((uint32_t*)client);
break;

case MQTT_MSG_TYPE_SUBACK:
if (pending_msg_type == MQTT_MSG_TYPE_SUBSCRIBE && pending_msg_id == msg_id) {
DBG_MQTT("MQTT: Subscribe successful\n");
//DBG_MQTT("MQTT: Subscribe successful\n");
client->pending_buffer = PktBuf_ShiftFree(client->pending_buffer);
}
break;

case MQTT_MSG_TYPE_UNSUBACK:
if (pending_msg_type == MQTT_MSG_TYPE_UNSUBSCRIBE && pending_msg_id == msg_id) {
DBG_MQTT("MQTT: Unsubscribe successful\n");
//DBG_MQTT("MQTT: Unsubscribe successful\n");
client->pending_buffer = PktBuf_ShiftFree(client->pending_buffer);
}
break;

case MQTT_MSG_TYPE_PUBACK: // ack for a publish we sent
if (pending_msg_type == MQTT_MSG_TYPE_PUBLISH && pending_msg_id == msg_id) {
DBG_MQTT("MQTT: QoS1 Publish successful\n");
//DBG_MQTT("MQTT: QoS1 Publish successful\n");
client->pending_buffer = PktBuf_ShiftFree(client->pending_buffer);
}
break;

case MQTT_MSG_TYPE_PUBREC: // rec for a publish we sent
if (pending_msg_type == MQTT_MSG_TYPE_PUBLISH && pending_msg_id == msg_id) {
DBG_MQTT("MQTT: QoS2 publish cont\n");
//DBG_MQTT("MQTT: QoS2 publish cont\n");
client->pending_buffer = PktBuf_ShiftFree(client->pending_buffer);
// we need to send PUBREL
mqtt_msg_pubrel(&client->mqtt_connection, msg_id);
Expand All @@ -202,7 +202,7 @@ mqtt_tcpclient_recv(void* arg, char* pdata, unsigned short len) {

case MQTT_MSG_TYPE_PUBCOMP: // comp for a pubrel we sent (originally publish we sent)
if (pending_msg_type == MQTT_MSG_TYPE_PUBREL && pending_msg_id == msg_id) {
DBG_MQTT("MQTT: QoS2 Publish successful\n");
//DBG_MQTT("MQTT: QoS2 Publish successful\n");
client->pending_buffer = PktBuf_ShiftFree(client->pending_buffer);
}
break;
Expand All @@ -228,7 +228,7 @@ mqtt_tcpclient_recv(void* arg, char* pdata, unsigned short len) {

case MQTT_MSG_TYPE_PUBREL: // rel for a rec we sent (originally publish received)
if (pending_msg_type == MQTT_MSG_TYPE_PUBREC && pending_msg_id == msg_id) {
DBG_MQTT("MQTT: Cont QoS2 recv\n");
//DBG_MQTT("MQTT: Cont QoS2 recv\n");
client->pending_buffer = PktBuf_ShiftFree(client->pending_buffer);
// we need to send PUBCOMP
mqtt_msg_pubcomp(&client->mqtt_connection, msg_id);
Expand Down Expand Up @@ -446,11 +446,13 @@ mqtt_send_message(MQTT_Client* client) {
msg_id = msg_id;
#ifdef MQTT_DBG
os_printf("MQTT: Send type=%s id=%04X len=%d\n", mqtt_msg_type[msg_type], msg_id, buf->filled);
#if 0
for (int i=0; i<buf->filled; i++) {
if (buf->data[i] >= ' ' && buf->data[i] <= '~') os_printf("%c", buf->data[i]);
else os_printf("\\x%02X", buf->data[i]);
}
os_printf("\n");
#endif
#endif

// send the message out
Expand Down Expand Up @@ -566,7 +568,7 @@ MQTT_Publish(MQTT_Client* client, const char* topic, const char* data, uint8_t q
buf->filled = msg.message.length;

DBG_MQTT("MQTT: Publish, topic: \"%s\", length: %d\n", topic, msg.message.length);
dumpMem(buf, buf_len);
//dumpMem(buf, buf_len);
client->msgQueue = PktBuf_Push(client->msgQueue, buf);

if (!client->sending && client->pending_buffer == NULL) {
Expand Down
Loading

0 comments on commit f057a65

Please sign in to comment.