From 121576cd150c7fcb529be0ff58cc70c168e5374c Mon Sep 17 00:00:00 2001 From: dannybackx Date: Mon, 31 Oct 2016 21:28:48 +0100 Subject: [PATCH] Bring code back, with changes cfr review --- cmd/cmd.h | 1 + cmd/handlers.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/cmd/cmd.h b/cmd/cmd.h index 3b4e8ab..a0abadf 100644 --- a/cmd/cmd.h +++ b/cmd/cmd.h @@ -42,6 +42,7 @@ typedef enum { CMD_CB_ADD, CMD_CB_EVENTS, CMD_GET_TIME, // get current time in seconds since the unix epoch + CMD_GET_WIFI_INFO, // query ip address info CMD_MQTT_SETUP = 10, // set-up callbacks CMD_MQTT_PUBLISH, // publish a message diff --git a/cmd/handlers.c b/cmd/handlers.c index c191091..09fd1de 100644 --- a/cmd/handlers.c +++ b/cmd/handlers.c @@ -17,6 +17,7 @@ #ifdef SOCKET #include #endif +#include #ifdef CMD_DBG #define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) @@ -44,6 +45,7 @@ const CmdList commands[] = { {CMD_WIFI_STATUS, "WIFI_STATUS", cmdWifiStatus}, {CMD_CB_ADD, "ADD_CB", cmdAddCallback}, {CMD_GET_TIME, "GET_TIME", cmdGetTime}, + {CMD_GET_WIFI_INFO, "GET_WIFI_INFO", cmdGetWifiInfo}, #ifdef MQTT {CMD_MQTT_SETUP, "MQTT_SETUP", MQTTCMD_Setup}, {CMD_MQTT_PUBLISH, "MQTT_PUB", MQTTCMD_Publish}, @@ -178,6 +180,30 @@ cmdGetTime(CmdPacket *cmd) { return; } +// Command handler for IP information +static void ICACHE_FLASH_ATTR +cmdGetWifiInfo(CmdPacket *cmd) { + CmdRequest req; + + cmdRequest(&req, cmd); + if(cmd->argc != 0 || cmd->value == 0) { + cmdResponseStart(CMD_RESP_V, 0, 0); + cmdResponseEnd(); + return; + } + + uint32_t callback = req.cmd->value; + + struct ip_info info; + wifi_get_ip_info(0, &info); + + cmdResponseStart(CMD_RESP_CB, callback, 3); + cmdResponseBody(&info.ip.addr, sizeof(info.ip.addr)); + cmdResponseBody(&info.netmask.addr, sizeof(info.netmask.addr)); + cmdResponseBody(&info.gw.addr, sizeof(info.gw.addr)); + cmdResponseEnd(); +} + // Command handler to add a callback to the named-callbacks list, this is for a callback to the uC static void ICACHE_FLASH_ATTR cmdAddCallback(CmdPacket *cmd) {