summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore11
-rw-r--r--polycom_xmit/Makefile15
-rw-r--r--polycom_xmit/gpio.c47
-rw-r--r--polycom_xmit/prototypes.h4
-rw-r--r--polycom_xmit/util.c10
-rw-r--r--polycom_xmit/webserver.c371
-rw-r--r--polycom_xmit/wifi.c5
7 files changed, 256 insertions, 207 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..6142876
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,11 @@
+iot/
+*.swp
+*.swo
+*.o
+*.bin
+*.0
+*.1
+*.2
+polycom_xmit/user0/
+polycom_xmit/user1/
+polycom_xmit/user2/
diff --git a/polycom_xmit/Makefile b/polycom_xmit/Makefile
index 1b4f0f6..28166d1 100644
--- a/polycom_xmit/Makefile
+++ b/polycom_xmit/Makefile
@@ -6,7 +6,7 @@ INCLUDES=-Idummy
GCCFLAGS=-fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -ffunction-sections -fdata-sections
-PORT=/dev/ttyUSB1
+PORT=/dev/ttyUSB0
#BAUD=-b 921600
#BAUD=-b 460800
#BAUD=-b 200000
@@ -25,12 +25,19 @@ PROG0=${PROG}.0
PROG1=${PROG}.1
PROG2=${PROG}.2
-SRC=main.c webserver.c util.c reset.c wifi.c uart.c upgrade.c
+SRC=main.c webserver.c util.c reset.c wifi.c uart.c upgrade.c gpio.c
+
+UART_BAUD=115200
+
+default: flash.stamp
+ sympathy -b ${UART_BAUD} -d ${PORT} -t -L log
+
+view:
+ sympathy -b ${UART_BAUD} -d ${PORT} -t -L log
-default: user0.bin
flash:flash.stamp
- sympathy -b 115200 -d ${PORT} -t -L log
+ sympathy -b ${UART_BAUD} -d ${PORT} -t -L log
flash.stamp: user0.bin
${EPSTOOL} ${BAUD} --port ${PORT} write_flash 0x00000 user0.bin 0x40000 user0/eagle.app.v6.irom0text.bin
diff --git a/polycom_xmit/gpio.c b/polycom_xmit/gpio.c
new file mode 100644
index 0000000..246beb8
--- /dev/null
+++ b/polycom_xmit/gpio.c
@@ -0,0 +1,47 @@
+#include "project.h"
+
+void ICACHE_FLASH_ATTR
+gpio_page (struct espconn *conn)
+{
+ char *page = os_zalloc (1024);
+ char *ptr = page;
+ int i;
+ uint32_t j, v;
+
+ if (!page)
+ {
+ webserver_send_reply (conn, 400, "text/html",
+ "<html><head></head><body>Out of memory</body></html>",
+ 0);
+ return;
+
+ }
+
+ ptr += os_sprintf (ptr, "<html><head>");
+
+ ptr += os_sprintf (ptr, "<style>\n"
+ "table {\n"
+ "border-collapse: collapse;\n"
+ "}\n"
+ "table, th, td {\n"
+ "border: 1px solid black;\n" "}\n" "</style>");
+
+ ptr += os_sprintf (ptr, "</head><body>");
+
+ v = gpio_input_get ();
+ ptr += os_sprintf (ptr, "<h2>GPIO: 0x%04x</h2><br/>", v);
+ ptr += os_sprintf (ptr, "<table>");
+ for (i = 0; i < 16; ++i)
+ {
+ j = 1 << i;
+ ptr +=
+ os_sprintf (ptr,
+ "<tr><td>%d</td><td>0x%04x</td><td>%s</td></tr>",
+ i, j, (j & v) ? "High" : "Low");
+ }
+
+
+ ptr += os_sprintf (ptr, "</table></body></html>");
+ webserver_send_reply (conn, 200, "text/html", page, ptr - page);
+ os_free (page);
+}
diff --git a/polycom_xmit/prototypes.h b/polycom_xmit/prototypes.h
index dc4d28d..64df8a2 100644
--- a/polycom_xmit/prototypes.h
+++ b/polycom_xmit/prototypes.h
@@ -2,10 +2,12 @@
void user_rf_pre_init(void);
void user_init(void);
/* webserver.c */
+void webserver_send_reply(struct espconn *conn, int status, char *type, char *body, size_t body_len);
void webserver_init(void);
/* util.c */
char *bounded_strstr(char *haystack, uint32_t len, char *needle);
bool util_isspace(char c);
+void crash(void);
/* reset.c */
void reset_init(void);
/* wifi.c */
@@ -15,3 +17,5 @@ STATUS uart0_tx_one_char(uint8 TxChar);
void uart_init(void);
/* upgrade.c */
void upgrade(void);
+/* gpio.c */
+void gpio_page(struct espconn *conn);
diff --git a/polycom_xmit/util.c b/polycom_xmit/util.c
index d637174..1d44f3d 100644
--- a/polycom_xmit/util.c
+++ b/polycom_xmit/util.c
@@ -1,7 +1,7 @@
#include "project.h"
-char *ICACHE_FLASH_ATTR
+ICACHE_FLASH_ATTR char *
bounded_strstr (char *haystack, uint32_t len, char *needle)
{
char *end = haystack + len;
@@ -45,3 +45,11 @@ util_isspace (char c)
return false;
}
}
+
+ICACHE_FLASH_ATTR void
+crash (void)
+{
+ char *c = NULL;
+
+ os_printf ("%d", *c);
+}
diff --git a/polycom_xmit/webserver.c b/polycom_xmit/webserver.c
index 5efc7cd..40be484 100644
--- a/polycom_xmit/webserver.c
+++ b/polycom_xmit/webserver.c
@@ -34,6 +34,58 @@ static http_state static_state = { 0 };
#define LENGTH_ERR ((uint32_t) -1)
+
+void ICACHE_FLASH_ATTR
+webserver_send_reply (struct espconn *conn, int status, char *type,
+ char *body, size_t body_len)
+{
+ char header[256] = { 0 };
+ char *ptr = header;
+
+ if (body && !body_len)
+ body_len = os_strlen (body);
+
+ switch (status)
+ {
+ case 200:
+ ptr +=
+ os_sprintf (ptr,
+ "HTTP/1.1 %d OK\r\nContent-Length: %d\r\nServer: InternetOfThingsThing/1.0\r\n",
+ status, body ? body_len : 0);
+
+ break;
+ default:
+ ptr +=
+ os_sprintf (ptr,
+ "HTTP/1.1 %d BadRequest\r\nContent-Length: %d\r\nServer: InternetOfThingsThing/1.0\r\n",
+ status, 0);
+ break;
+ }
+ if (body && body_len)
+ {
+
+ if (type)
+ ptr +=
+ os_sprintf (ptr,
+ "Content-type: %s\r\nExpires: Fri, 10 Apr 2008 14:00:00 GMT\r\nPragma: no-cache\r\n",
+ type);
+ }
+
+ ptr += os_sprintf (ptr, "Connection: close\r\n\r\n");
+
+#ifdef SERVER_SSL_ENABLE
+ espconn_secure_sent (conn, header, (uint32_t) ptr - header);
+ if (body && body_len)
+ espconn_secure_sent (conn, body, body_len);
+#else
+ espconn_sent (conn, header, (uint32_t) (ptr - header));
+ if (body && body_len)
+ espconn_sent (conn, body, body_len);
+#endif
+
+}
+
+
static bool ICACHE_FLASH_ATTR
webserver_get_header (char *buf, uint32_t length, char *match, char *ret,
uint32_t ret_len)
@@ -150,9 +202,11 @@ webserver_parse_header (http_state * s, char *buf, uint32_t length)
s->header_parsed_ok = false;
+
if (s->error)
return false;
+
eoh_ptr = (char *) bounded_strstr (buf, length, "\r\n\r\n");
if (!eoh_ptr)
@@ -172,16 +226,18 @@ webserver_parse_header (http_state * s, char *buf, uint32_t length)
else
{
s->content_length = atoi (tmp_buf);
- if (s->content_length <= 0)
+ if (s->content_length < 0)
return false;
}
+
if (!webserver_parse_request (s, buf))
{
s->error++;
return false;
}
+
s->header_parsed_ok = true;
s->expected_length = s->content_length + s->header_length;
@@ -264,31 +320,38 @@ webserver_header (http_state * s)
{
-}
+}
static void ICACHE_FLASH_ATTR
-webserver_req (http_state * s)
+webserver_req (struct espconn *conn, http_state * s)
{
os_printf ("Webserver req: %s\n", s->url);
-
- if (os_strstr (s->url, "upgrade"))
+ if (!os_strcmp (s->url, "/crash.html"))
+ {
+ webserver_send_reply (conn, 200, "text/html",
+ "<html><head></head><body>crashed into monitor</body></html>",
+ 0);
+ crash ();
+ }
+ else if (os_strstr (s->url, "/upgrade.html"))
{
+ webserver_send_reply (conn, 200, "text/html",
+ "<html><head></head><body>triggered upgrade</body></html>",
+ 0);
os_printf ("Upgrading\n");
upgrade ();
}
-
- if (os_strstr (s->url, "reboot"))
+ else if (os_strstr (s->url, "/gpio.html"))
{
- os_printf ("Rebooting\n");
- //system_upgrade_reboot();
- //xtbsp_board_reset();
- //
- char *c = NULL;
-
- os_printf ("%d", *c);
+ gpio_page (conn);
+ }
+ else
+ {
+ webserver_send_reply (conn, 404, "text/html",
+ "<html><head></head><body>Not Found</body></html>",
+ 0);
}
-
}
@@ -298,24 +361,19 @@ webserver_req (http_state * s)
static void ICACHE_FLASH_ATTR
webserver_recv (void *arg, char *pusrdata, unsigned short data_len)
{
- struct espconn *ptrespconn = arg;
+ struct espconn *conn = arg;
uint32_t len;
http_state *s = &static_state;
-
-
#if 0
if (doing_upgrade)
{
upgrade_recv (ptrespconn, pusrdata, data_len);
free_recvbuffer ();
-
return;
}
#endif
os_printf ("len:%u\n", data_len);
-
-
if (!s->header_parsed_ok)
{
if (!s->recv_buffer)
@@ -342,12 +400,9 @@ webserver_recv (void *arg, char *pusrdata, unsigned short data_len)
if (s->error)
return;
-
if (s->bytes_recvd != s->expected_length)
return;
-
- webserver_req (s);
-
+ webserver_req (conn, s);
}
@@ -355,20 +410,19 @@ static ICACHE_FLASH_ATTR void
webserver_recon (void *arg, sint8 err)
{
struct espconn *pesp_conn = arg;
-
- os_printf ("webserver's %d.%d.%d.%d:%d err %d reconnect\n",
- pesp_conn->proto.tcp->remote_ip[0],
- pesp_conn->proto.tcp->remote_ip[1],
- pesp_conn->proto.tcp->remote_ip[2],
- pesp_conn->proto.tcp->remote_ip[3],
- pesp_conn->proto.tcp->remote_port, err);
+ os_printf
+ ("webserver's %d.%d.%d.%d:%d err %d reconnect\n",
+ pesp_conn->proto.tcp->remote_ip[0],
+ pesp_conn->proto.tcp->remote_ip[1],
+ pesp_conn->proto.tcp->remote_ip[2],
+ pesp_conn->proto.tcp->remote_ip[3],
+ pesp_conn->proto.tcp->remote_port, err);
}
static ICACHE_FLASH_ATTR void
webserver_discon (void *arg)
{
struct espconn *pesp_conn = arg;
-
os_printf ("webserver's %d.%d.%d.%d:%d disconnect\n",
pesp_conn->proto.tcp->remote_ip[0],
pesp_conn->proto.tcp->remote_ip[1],
@@ -384,9 +438,7 @@ static void ICACHE_FLASH_ATTR
webserver_listen (void *arg)
{
struct espconn *pesp_conn = arg;
-
webserver_state_reset (&static_state);
-
espconn_regist_recvcb (pesp_conn, webserver_recv);
espconn_regist_reconcb (pesp_conn, webserver_recon);
espconn_regist_disconcb (pesp_conn, webserver_discon);
@@ -398,7 +450,6 @@ webserver_init (void)
{
static struct espconn esp_conn;
static esp_tcp esptcp;
-
esp_conn.type = ESPCONN_TCP;
esp_conn.state = ESPCONN_NONE;
esp_conn.proto.tcp = &esptcp;
@@ -407,9 +458,7 @@ webserver_init (void)
#else
esp_conn.proto.tcp->local_port = 80;
#endif
-
espconn_regist_connectcb (&esp_conn, webserver_listen);
-
#ifdef HTTPS
espconn_secure_accept (&esp_conn);
#else
@@ -453,20 +502,15 @@ webserver_init (void)
static struct station_config *sta_conf;
static struct softap_config *ap_conf;
-
//static struct secrty_server_info *sec_server;
//static struct upgrade_server_info *server;
//struct lewei_login_info *login_info;
static scaninfo *pscaninfo;
-
extern u16 scannum;
-
static uint32 PostCmdNeeRsp = 1;
-
uint8 upgrade_lock = 0;
static os_timer_t app_upgrade_10s;
static os_timer_t upgrade_check_timer;
-
/******************************************************************************
* FunctionName : device_get
* Description : set up the device information parmer as a JSON format
@@ -477,7 +521,6 @@ static int ICACHE_FLASH_ATTR
device_get (struct jsontree_context *js_ctx)
{
const char *path = jsontree_path_name (js_ctx, js_ctx->depth - 1);
-
if (os_strncmp (path, "manufacture", 11) == 0)
{
jsontree_write_string (js_ctx, "Espressif Systems");
@@ -515,7 +558,6 @@ userbin_get (struct jsontree_context *js_ctx)
{
const char *path = jsontree_path_name (js_ctx, js_ctx->depth - 1);
char string[32];
-
if (os_strncmp (path, "status", 8) == 0)
{
os_sprintf (string, "200");
@@ -537,15 +579,14 @@ userbin_get (struct jsontree_context *js_ctx)
}
jsontree_write_string (js_ctx, string);
-
return 0;
}
static struct jsontree_callback userbin_callback =
JSONTREE_CALLBACK (userbin_get, NULL);
-
JSONTREE_OBJECT (userbin_tree,
- JSONTREE_PAIR ("status", &userbin_callback),
+ JSONTREE_PAIR ("status",
+ &userbin_callback),
JSONTREE_PAIR ("user_bin", &userbin_callback));
JSONTREE_OBJECT (userinfo_tree, JSONTREE_PAIR ("user_info", &userbin_tree));
/******************************************************************************
@@ -559,7 +600,6 @@ version_get (struct jsontree_context *js_ctx)
{
const char *path = jsontree_path_name (js_ctx, js_ctx->depth - 1);
char string[32];
-
if (os_strncmp (path, "hardware", 8) == 0)
{
#if SENSOR_DEVICE
@@ -575,36 +615,35 @@ version_get (struct jsontree_context *js_ctx)
else if (os_strncmp (path, "iot_version", 11) == 0)
{
os_sprintf (string, "%s%d.%d.%dt%d(%s)", VERSION_TYPE,
- IOT_VERSION_MAJOR, IOT_VERSION_MINOR, IOT_VERSION_REVISION,
- device_type, UPGRADE_FALG);
+ IOT_VERSION_MAJOR, IOT_VERSION_MINOR,
+ IOT_VERSION_REVISION, device_type, UPGRADE_FALG);
}
jsontree_write_string (js_ctx, string);
-
return 0;
}
static struct jsontree_callback version_callback =
JSONTREE_CALLBACK (version_get, NULL);
-
JSONTREE_OBJECT (device_tree,
- JSONTREE_PAIR ("product", &device_callback),
+ JSONTREE_PAIR ("product",
+ &device_callback),
JSONTREE_PAIR ("manufacturer", &device_callback));
JSONTREE_OBJECT (version_tree,
- JSONTREE_PAIR ("hardware", &version_callback),
- JSONTREE_PAIR ("sdk_version", &version_callback),
+ JSONTREE_PAIR ("hardware",
+ &version_callback),
+ JSONTREE_PAIR ("sdk_version",
+ &version_callback),
JSONTREE_PAIR ("iot_version", &version_callback),);
JSONTREE_OBJECT (info_tree,
- JSONTREE_PAIR ("Version", &version_tree),
+ JSONTREE_PAIR ("Version",
+ &version_tree),
JSONTREE_PAIR ("Device", &device_tree));
-
JSONTREE_OBJECT (INFOTree, JSONTREE_PAIR ("info", &info_tree));
-
static int ICACHE_FLASH_ATTR
connect_status_get (struct jsontree_context *js_ctx)
{
const char *path = jsontree_path_name (js_ctx, js_ctx->depth - 1);
-
if (os_strncmp (path, "status", 8) == 0)
{
jsontree_write_int (js_ctx, user_esp_platform_get_connect_status ());
@@ -615,16 +654,12 @@ connect_status_get (struct jsontree_context *js_ctx)
static struct jsontree_callback connect_status_callback =
JSONTREE_CALLBACK (connect_status_get, NULL);
-
JSONTREE_OBJECT (status_sub_tree,
JSONTREE_PAIR ("status", &connect_status_callback));
-
JSONTREE_OBJECT (connect_status_tree,
JSONTREE_PAIR ("Status", &status_sub_tree));
-
JSONTREE_OBJECT (con_status_tree,
JSONTREE_PAIR ("info", &connect_status_tree));
-
#if PLUG_DEVICE
/******************************************************************************
* FunctionName : status_get
@@ -658,7 +693,6 @@ static int ICACHE_FLASH_ATTR
status_set (struct jsontree_context *js_ctx, struct jsonparse_state *parser)
{
int type;
-
while ((type = jsonparse_next (parser)) != 0)
{
if (type == JSON_TYPE_PAIR_NAME)
@@ -679,18 +713,15 @@ status_set (struct jsontree_context *js_ctx, struct jsonparse_state *parser)
static struct jsontree_callback status_callback =
JSONTREE_CALLBACK (status_get, status_set);
-
JSONTREE_OBJECT (status_tree, JSONTREE_PAIR ("status", &status_callback));
JSONTREE_OBJECT (response_tree, JSONTREE_PAIR ("Response", &status_tree));
JSONTREE_OBJECT (StatusTree, JSONTREE_PAIR ("switch", &response_tree));
#endif
-
#if LIGHT_DEVICE
static int ICACHE_FLASH_ATTR
light_status_get (struct jsontree_context *js_ctx)
{
const char *path = jsontree_path_name (js_ctx, js_ctx->depth - 1);
-
if (os_strncmp (path, "red", 3) == 0)
{
jsontree_write_int (js_ctx, user_light_get_duty (LIGHT_RED));
@@ -743,7 +774,6 @@ light_status_set (struct jsontree_context *js_ctx,
cw = 0;
ww = 0;
extern uint8 light_sleep_flg;
-
while ((type = jsonparse_next (parser)) != 0)
{
if (type == JSON_TYPE_PAIR_NAME)
@@ -821,7 +851,6 @@ light_status_set (struct jsontree_context *js_ctx,
status = jsonparse_get_value_as_int (parser);
os_printf ("rspneed: %d \n", status);
PostCmdNeeRsp = status;
-
}
}
}
@@ -849,19 +878,20 @@ light_status_set (struct jsontree_context *js_ctx,
static struct jsontree_callback light_callback =
JSONTREE_CALLBACK (light_status_get, light_status_set);
-
JSONTREE_OBJECT (rgb_tree,
JSONTREE_PAIR ("red", &light_callback),
- JSONTREE_PAIR ("green", &light_callback),
+ JSONTREE_PAIR ("green",
+ &light_callback),
JSONTREE_PAIR ("blue", &light_callback),
- JSONTREE_PAIR ("cwhite", &light_callback),
+ JSONTREE_PAIR ("cwhite",
+ &light_callback),
JSONTREE_PAIR ("wwhite", &light_callback),);
JSONTREE_OBJECT (sta_tree,
- JSONTREE_PAIR ("period", &light_callback),
+ JSONTREE_PAIR ("period",
+ &light_callback),
JSONTREE_PAIR ("rgb", &rgb_tree));
JSONTREE_OBJECT (PwmTree, JSONTREE_PAIR ("light", &sta_tree));
#endif
-
/******************************************************************************
* FunctionName : wifi_station_get
* Description : set up the station paramer as a JSON format
@@ -877,7 +907,6 @@ wifi_station_get (struct jsontree_context *js_ctx)
os_bzero (buf, sizeof (buf));
wifi_station_get_config (sta_conf);
wifi_get_ip_info (STATION_IF, &ipconfig);
-
if (os_strncmp (path, "ssid", 4) == 0)
{
jsontree_write_string (js_ctx, sta_conf->ssid);
@@ -918,14 +947,12 @@ wifi_station_set (struct jsontree_context *js_ctx,
{
int type;
uint8 station_tree;
-
while ((type = jsonparse_next (parser)) != 0)
{
if (type == JSON_TYPE_PAIR_NAME)
{
char buffer[64];
os_bzero (buffer, 64);
-
if (jsonparse_strcmp_value (parser, "Station") == 0)
{
station_tree = 1;
@@ -972,30 +999,32 @@ wifi_station_set (struct jsontree_context *js_ctx,
static struct jsontree_callback wifi_station_callback =
JSONTREE_CALLBACK (wifi_station_get, wifi_station_set);
-
JSONTREE_OBJECT (get_station_config_tree,
- JSONTREE_PAIR ("ssid", &wifi_station_callback),
+ JSONTREE_PAIR ("ssid",
+ &wifi_station_callback),
JSONTREE_PAIR ("password", &wifi_station_callback));
JSONTREE_OBJECT (set_station_config_tree,
- JSONTREE_PAIR ("ssid", &wifi_station_callback),
- JSONTREE_PAIR ("password", &wifi_station_callback),
+ JSONTREE_PAIR ("ssid",
+ &wifi_station_callback),
+ JSONTREE_PAIR ("password",
+ &wifi_station_callback),
JSONTREE_PAIR ("token", &wifi_station_callback));
-
JSONTREE_OBJECT (ip_tree,
- JSONTREE_PAIR ("ip", &wifi_station_callback),
- JSONTREE_PAIR ("mask", &wifi_station_callback),
+ JSONTREE_PAIR ("ip",
+ &wifi_station_callback),
+ JSONTREE_PAIR ("mask",
+ &wifi_station_callback),
JSONTREE_PAIR ("gw", &wifi_station_callback));
JSONTREE_OBJECT (get_station_tree,
- JSONTREE_PAIR ("Connect_Station", &get_station_config_tree),
+ JSONTREE_PAIR ("Connect_Station",
+ &get_station_config_tree),
JSONTREE_PAIR ("Ipinfo_Station", &ip_tree));
JSONTREE_OBJECT (set_station_tree,
JSONTREE_PAIR ("Connect_Station", &set_station_config_tree));
-
//JSONTREE_OBJECT(get_wifi_station_info_tree,
// JSONTREE_PAIR("Station", &get_station_tree));
//JSONTREE_OBJECT(set_wifi_station_info_tree,
// JSONTREE_PAIR("station", &set_station_tree));
-
/******************************************************************************
* FunctionName : wifi_softap_get
* Description : set up the softap paramer as a JSON format
@@ -1011,7 +1040,6 @@ wifi_softap_get (struct jsontree_context *js_ctx)
os_bzero (buf, sizeof (buf));
wifi_softap_get_config (ap_conf);
wifi_get_ip_info (SOFTAP_IF, &ipconfig);
-
if (os_strncmp (path, "ssid", 4) == 0)
{
jsontree_write_string (js_ctx, ap_conf->ssid);
@@ -1031,23 +1059,18 @@ wifi_softap_get (struct jsontree_context *js_ctx)
case AUTH_OPEN:
jsontree_write_string (js_ctx, "OPEN");
break;
-
case AUTH_WEP:
jsontree_write_string (js_ctx, "WEP");
break;
-
case AUTH_WPA_PSK:
jsontree_write_string (js_ctx, "WPAPSK");
break;
-
case AUTH_WPA2_PSK:
jsontree_write_string (js_ctx, "WPA2PSK");
break;
-
case AUTH_WPA_WPA2_PSK:
jsontree_write_string (js_ctx, "WPAPSK/WPA2PSK");
break;
-
default:
jsontree_write_int (js_ctx, ap_conf->authmode);
break;
@@ -1085,14 +1108,12 @@ wifi_softap_set (struct jsontree_context *js_ctx,
{
int type;
uint8 softap_tree;
-
while ((type = jsonparse_next (parser)) != 0)
{
if (type == JSON_TYPE_PAIR_NAME)
{
char buffer[64];
os_bzero (buffer, 64);
-
if (jsonparse_strcmp_value (parser, "Station") == 0)
{
softap_tree = 0;
@@ -1109,7 +1130,6 @@ wifi_softap_set (struct jsontree_context *js_ctx,
jsonparse_next (parser);
jsonparse_next (parser);
jsonparse_copy_value (parser, buffer, sizeof (buffer));
-
// other mode will be supported later...
if (os_strcmp (buffer, "OPEN") == 0)
{
@@ -1164,38 +1184,40 @@ wifi_softap_set (struct jsontree_context *js_ctx,
static struct jsontree_callback wifi_softap_callback =
JSONTREE_CALLBACK (wifi_softap_get, wifi_softap_set);
-
JSONTREE_OBJECT (softap_config_tree,
- JSONTREE_PAIR ("authmode", &wifi_softap_callback),
- JSONTREE_PAIR ("channel", &wifi_softap_callback),
- JSONTREE_PAIR ("ssid", &wifi_softap_callback),
+ JSONTREE_PAIR ("authmode",
+ &wifi_softap_callback),
+ JSONTREE_PAIR ("channel",
+ &wifi_softap_callback),
+ JSONTREE_PAIR ("ssid",
+ &wifi_softap_callback),
JSONTREE_PAIR ("password", &wifi_softap_callback));
JSONTREE_OBJECT (softap_ip_tree,
- JSONTREE_PAIR ("ip", &wifi_softap_callback),
- JSONTREE_PAIR ("mask", &wifi_softap_callback),
+ JSONTREE_PAIR ("ip",
+ &wifi_softap_callback),
+ JSONTREE_PAIR ("mask",
+ &wifi_softap_callback),
JSONTREE_PAIR ("gw", &wifi_softap_callback));
JSONTREE_OBJECT (get_softap_tree,
- JSONTREE_PAIR ("Connect_Softap", &softap_config_tree),
+ JSONTREE_PAIR ("Connect_Softap",
+ &softap_config_tree),
JSONTREE_PAIR ("Ipinfo_Softap", &softap_ip_tree));
JSONTREE_OBJECT (set_softap_tree,
JSONTREE_PAIR ("Ipinfo_Softap", &softap_config_tree));
-
JSONTREE_OBJECT (get_wifi_tree,
- JSONTREE_PAIR ("Station", &get_station_tree),
+ JSONTREE_PAIR ("Station",
+ &get_station_tree),
JSONTREE_PAIR ("Softap", &get_softap_tree));
JSONTREE_OBJECT (set_wifi_tree,
- JSONTREE_PAIR ("Station", &set_station_tree),
+ JSONTREE_PAIR ("Station",
+ &set_station_tree),
JSONTREE_PAIR ("Softap", &set_softap_tree));
-
JSONTREE_OBJECT (wifi_response_tree,
JSONTREE_PAIR ("Response", &get_wifi_tree));
JSONTREE_OBJECT (wifi_request_tree,
JSONTREE_PAIR ("Request", &set_wifi_tree));
-
JSONTREE_OBJECT (wifi_info_tree, JSONTREE_PAIR ("wifi", &wifi_response_tree));
JSONTREE_OBJECT (wifi_req_tree, JSONTREE_PAIR ("wifi", &wifi_request_tree));
-
-
/******************************************************************************
* FunctionName : scan_get
* Description : set up the scan data as a JSON format
@@ -1208,7 +1230,6 @@ scan_get (struct jsontree_context *js_ctx)
const char *path = jsontree_path_name (js_ctx, js_ctx->depth - 1);
// STAILQ_HEAD(, bss_info) *pbss = scanarg;
static struct bss_info *bss;
-
if (os_strncmp (path, "TotalPage", 9) == 0)
{
jsontree_write_int (js_ctx, pscaninfo->totalpage);
@@ -1250,23 +1271,18 @@ scan_get (struct jsontree_context *js_ctx)
case AUTH_OPEN:
jsontree_write_string (js_ctx, "OPEN");
break;
-
case AUTH_WEP:
jsontree_write_string (js_ctx, "WEP");
break;
-
case AUTH_WPA_PSK:
jsontree_write_string (js_ctx, "WPAPSK");
break;
-
case AUTH_WPA2_PSK:
jsontree_write_string (js_ctx, "WPA2PSK");
break;
-
case AUTH_WPA_WPA2_PSK:
jsontree_write_string (js_ctx, "WPAPSK/WPA2PSK");
break;
-
default:
jsontree_write_int (js_ctx, bss->authmode);
break;
@@ -1282,12 +1298,12 @@ scan_get (struct jsontree_context *js_ctx)
static struct jsontree_callback scan_callback =
JSONTREE_CALLBACK (scan_get, NULL);
-
JSONTREE_OBJECT (scaninfo_tree,
JSONTREE_PAIR ("bssid", &scan_callback),
JSONTREE_PAIR ("ssid", &scan_callback),
JSONTREE_PAIR ("rssi", &scan_callback),
- JSONTREE_PAIR ("channel", &scan_callback),
+ JSONTREE_PAIR ("channel",
+ &scan_callback),
JSONTREE_PAIR ("authmode", &scan_callback));
JSONTREE_ARRAY (scanrslt_tree,
JSONTREE_PAIR_ARRAY (&scaninfo_tree),
@@ -1298,14 +1314,14 @@ JSONTREE_ARRAY (scanrslt_tree,
JSONTREE_PAIR_ARRAY (&scaninfo_tree),
JSONTREE_PAIR_ARRAY (&scaninfo_tree),
JSONTREE_PAIR_ARRAY (&scaninfo_tree));
-
JSONTREE_OBJECT (scantree,
- JSONTREE_PAIR ("TotalPage", &scan_callback),
- JSONTREE_PAIR ("PageNum", &scan_callback),
+ JSONTREE_PAIR ("TotalPage",
+ &scan_callback),
+ JSONTREE_PAIR ("PageNum",
+ &scan_callback),
JSONTREE_PAIR ("ScanResult", &scanrslt_tree));
JSONTREE_OBJECT (scanres_tree, JSONTREE_PAIR ("Response", &scantree));
JSONTREE_OBJECT (scan_tree, JSONTREE_PAIR ("scan", &scanres_tree));
-
/******************************************************************************
* FunctionName : parse_url
* Description : parse the received data from the server
@@ -1320,14 +1336,12 @@ parse_url (char *precv, URL_Frame * purl_frame)
uint8 length = 0;
char *pbuffer = NULL;
char *pbufer = NULL;
-
if (purl_frame == NULL || precv == NULL)
{
return;
}
pbuffer = (char *) os_strstr (precv, "Host:");
-
if (pbuffer != NULL)
{
length = pbuffer - precv;
@@ -1337,7 +1351,6 @@ parse_url (char *precv, URL_Frame * purl_frame)
os_memset (purl_frame->pSelect, 0, URLSize);
os_memset (purl_frame->pCommand, 0, URLSize);
os_memset (purl_frame->pFilename, 0, URLSize);
-
if (os_strncmp (pbuffer, "GET ", 4) == 0)
{
purl_frame->Type = GET;
@@ -1351,21 +1364,18 @@ parse_url (char *precv, URL_Frame * purl_frame)
pbuffer++;
str = (char *) os_strstr (pbuffer, "?");
-
if (str != NULL)
{
length = str - pbuffer;
os_memcpy (purl_frame->pSelect, pbuffer, length);
str++;
pbuffer = (char *) os_strstr (str, "=");
-
if (pbuffer != NULL)
{
length = pbuffer - str;
os_memcpy (purl_frame->pCommand, str, length);
pbuffer++;
str = (char *) os_strstr (pbuffer, "&");
-
if (str != NULL)
{
length = str - pbuffer;
@@ -1374,7 +1384,6 @@ parse_url (char *precv, URL_Frame * purl_frame)
else
{
str = (char *) os_strstr (pbuffer, " HTTP");
-
if (str != NULL)
{
length = str - pbuffer;
@@ -1398,14 +1407,14 @@ static bool ICACHE_FLASH_ATTR
save_data (char *precv, uint16 length)
{
bool flag = false;
- char length_buf[10] = { 0 };
+ char length_buf[10] = {
+ 0
+ };
char *ptemp = NULL;
char *pdata = NULL;
uint16 headlength = 0;
static uint32 totallength = 0;
-
ptemp = (char *) os_strstr (precv, "\r\n\r\n");
-
if (ptemp != NULL)
{
length -= ptemp - precv;
@@ -1413,12 +1422,10 @@ save_data (char *precv, uint16 length)
totallength += length;
headlength = ptemp - precv + 4;
pdata = (char *) os_strstr (precv, "Content-Length: ");
-
if (pdata != NULL)
{
pdata += 16;
precvbuffer = (char *) os_strstr (pdata, "\r\n");
-
if (precvbuffer != NULL)
{
os_memcpy (length_buf, pdata, precvbuffer - pdata);
@@ -1476,28 +1483,25 @@ static bool ICACHE_FLASH_ATTR
check_data (char *precv, uint16 length)
{
//bool flag = true;
- char length_buf[10] = { 0 };
+ char length_buf[10] = {
+ 0
+ };
char *ptemp = NULL;
char *pdata = NULL;
char *tmp_precvbuffer;
uint16 tmp_length = length;
uint32 tmp_totallength = 0;
-
ptemp = (char *) os_strstr (precv, "\r\n\r\n");
-
if (ptemp != NULL)
{
tmp_length -= ptemp - precv;
tmp_length -= 4;
tmp_totallength += tmp_length;
-
pdata = (char *) os_strstr (precv, "Content-Length: ");
-
if (pdata != NULL)
{
pdata += 16;
tmp_precvbuffer = (char *) os_strstr (pdata, "\r\n");
-
if (tmp_precvbuffer != NULL)
{
os_memcpy (length_buf, pdata, tmp_precvbuffer - pdata);
@@ -1516,7 +1520,6 @@ check_data (char *precv, uint16 length)
static os_timer_t *restart_10ms;
static rst_parm *rstparm;
-
/******************************************************************************
* FunctionName : restart_10ms_cb
* Description : system restart or wifi reconnected after a certain time.
@@ -1557,15 +1560,12 @@ restart_10ms_cb (void *arg)
//} else {
// os_timer_arm(restart_10ms, 10, 0);
//}
-
break;
-
case DEEP_SLEEP:
case REBOOT:
if (rstparm->pespconn->state == ESPCONN_CLOSE)
{
wifi_set_opmode (STATION_MODE);
-
if (rstparm->parmtype == DEEP_SLEEP)
{
#if SENSOR_DEVICE
@@ -1579,7 +1579,6 @@ restart_10ms_cb (void *arg)
}
break;
-
default:
break;
}
@@ -1602,13 +1601,11 @@ data_send (void *arg, bool responseOK, char *psend)
char httphead[256];
struct espconn *ptrespconn = arg;
os_memset (httphead, 0, 256);
-
if (responseOK)
{
os_sprintf (httphead,
"HTTP/1.0 200 OK\r\nContent-Length: %d\r\nServer: lwIP/1.4.0\r\n",
psend ? os_strlen (psend) : 0);
-
if (psend)
{
os_sprintf (httphead + os_strlen (httphead),
@@ -1668,7 +1665,6 @@ json_send (void *arg, ParmType ParmType)
char *pbuf = NULL;
pbuf = (char *) os_zalloc (jsonSize);
struct espconn *ptrespconn = arg;
-
switch (ParmType)
{
#if LIGHT_DEVICE
@@ -1677,26 +1673,20 @@ json_send (void *arg, ParmType ParmType)
json_ws_send ((struct jsontree_value *) &PwmTree, "light", pbuf);
break;
#endif
-
#if PLUG_DEVICE
-
case SWITCH_STATUS:
json_ws_send ((struct jsontree_value *) &StatusTree, "switch", pbuf);
break;
#endif
-
case INFOMATION:
json_ws_send ((struct jsontree_value *) &INFOTree, "info", pbuf);
break;
-
case WIFI:
json_ws_send ((struct jsontree_value *) &wifi_info_tree, "wifi", pbuf);
break;
-
case CONNECT_STATUS:
json_ws_send ((struct jsontree_value *) &con_status_tree, "info", pbuf);
break;
-
case USER_BIN:
json_ws_send ((struct jsontree_value *) &userinfo_tree, "user_info",
pbuf);
@@ -1707,7 +1697,6 @@ json_send (void *arg, ParmType ParmType)
u8 scancount = 0;
struct bss_info *bss = NULL;
bss = STAILQ_FIRST (pscaninfo->pbss);
-
if (bss == NULL)
{
os_free (pscaninfo);
@@ -1727,12 +1716,10 @@ json_send (void *arg, ParmType ParmType)
}
scancount = scannum - (pscaninfo->pagenum - 1) * 8;
-
if (scancount >= 8)
{
pscaninfo->data_cnt += 8;
pscaninfo->page_sn = pscaninfo->pagenum;
-
if (pscaninfo->data_cnt > scannum)
{
pscaninfo->data_cnt -= 8;
@@ -1748,7 +1735,6 @@ json_send (void *arg, ParmType ParmType)
{
pscaninfo->data_cnt += scancount;
pscaninfo->page_sn = pscaninfo->pagenum;
-
if (pscaninfo->data_cnt > scannum)
{
pscaninfo->data_cnt -= scancount;
@@ -1761,7 +1747,6 @@ json_send (void *arg, ParmType ParmType)
char *pscanbuf = ptrscanbuf;
os_sprintf (pscanbuf, ",\n\"ScanResult\": [\n");
pscanbuf += os_strlen (pscanbuf);
-
for (i = 0; i < scancount; i++)
{
JSONTREE_OBJECT (page_tree,
@@ -1817,7 +1802,6 @@ static void ICACHE_FLASH_ATTR
response_send (void *arg, bool responseOK)
{
struct espconn *ptrespconn = arg;
-
data_send (ptrespconn, responseOK, NULL);
}
@@ -1832,7 +1816,6 @@ static void ICACHE_FLASH_ATTR
json_scan_cb (void *arg, STATUS status)
{
pscaninfo->pbss = arg;
-
if (scannum % 8 == 0)
{
pscaninfo->totalpage = scannum / 8;
@@ -1845,7 +1828,6 @@ json_scan_cb (void *arg, STATUS status)
JSONTREE_OBJECT (totaltree, JSONTREE_PAIR ("TotalPage", &scan_callback));
JSONTREE_OBJECT (totalres_tree, JSONTREE_PAIR ("Response", &totaltree));
JSONTREE_OBJECT (total_tree, JSONTREE_PAIR ("total", &totalres_tree));
-
char *pbuf = NULL;
pbuf = (char *) os_zalloc (jsonSize);
json_ws_send ((struct jsontree_value *) &total_tree, "total", pbuf);
@@ -1913,11 +1895,17 @@ local_upgrade_download (void *arg, char *pusrdata, unsigned short length)
char lengthbuffer[32];
static uint32 totallength = 0;
static uint32 sumlength = 0;
- char A_buf[2] = { 0xE9, 0x03 };
- char B_buf[2] = { 0xEA, 0x04 };
+ char A_buf[2] = {
+ 0xE9, 0x03
+ };
+ char B_buf[2] = {
+ 0xEA, 0x04
+ };
struct espconn *pespconn = arg;
if (totallength == 0
- && (ptr = (char *) os_strstr (pusrdata, "\r\n\r\n")) != NULL
+ && (ptr =
+ (char *) os_strstr (pusrdata,
+ "\r\n\r\n")) != NULL
&& (ptr = (char *) os_strstr (pusrdata, "Content-Length")) != NULL)
{
ptr = (char *) os_strstr (pusrdata, "Content-Length: ");
@@ -1925,7 +1913,6 @@ local_upgrade_download (void *arg, char *pusrdata, unsigned short length)
{
ptr += 16;
ptmp2 = (char *) os_strstr (ptr, "\r\n");
-
if (ptmp2 != NULL)
{
os_memset (lengthbuffer, 0, sizeof (lengthbuffer));
@@ -1951,7 +1938,6 @@ local_upgrade_download (void *arg, char *pusrdata, unsigned short length)
totallength += length;
os_printf ("upgrade file download start.\n");
system_upgrade (ptr + 4, length);
-
}
else
{
@@ -1988,7 +1974,6 @@ webserver_recv (void *arg, char *pusrdata, unsigned short length)
char *pParseBuffer = NULL;
bool parse_flag = false;
struct espconn *ptrespconn = arg;
-
if (upgrade_lock == 0)
{
@@ -2008,12 +1993,10 @@ webserver_recv (void *arg, char *pusrdata, unsigned short length)
// os_printf(precvbuffer);
pURL_Frame = (URL_Frame *) os_zalloc (sizeof (URL_Frame));
parse_url (precvbuffer, pURL_Frame);
-
switch (pURL_Frame->Type)
{
case GET:
os_printf ("We have a GET request.\n");
-
if (os_strcmp (pURL_Frame->pSelect, "client") == 0 &&
os_strcmp (pURL_Frame->pCommand, "command") == 0)
{
@@ -2030,7 +2013,6 @@ webserver_recv (void *arg, char *pusrdata, unsigned short length)
{
char *strstr = NULL;
strstr = (char *) os_strstr (pusrdata, "&");
-
if (strstr == NULL)
{
if (pscaninfo == NULL)
@@ -2048,14 +2030,12 @@ webserver_recv (void *arg, char *pusrdata, unsigned short length)
else
{
strstr++;
-
if (os_strncmp (strstr, "page", 4) == 0)
{
if (pscaninfo != NULL)
{
pscaninfo->pagenum = *(strstr + 5);
pscaninfo->pagenum -= 0x30;
-
if (pscaninfo->pagenum > pscaninfo->totalpage
|| pscaninfo->pagenum == 0)
{
@@ -2082,8 +2062,9 @@ webserver_recv (void *arg, char *pusrdata, unsigned short length)
response_send (ptrespconn, false);
}
}
- else if (os_strcmp (pURL_Frame->pSelect, "config") == 0 &&
- os_strcmp (pURL_Frame->pCommand, "command") == 0)
+ else
+ if (os_strcmp (pURL_Frame->pSelect, "config") == 0 &&
+ os_strcmp (pURL_Frame->pCommand, "command") == 0)
{
if (os_strcmp (pURL_Frame->pFilename, "wifi") == 0)
{
@@ -2126,8 +2107,9 @@ webserver_recv (void *arg, char *pusrdata, unsigned short length)
response_send (ptrespconn, false);
}
}
- else if (os_strcmp (pURL_Frame->pSelect, "upgrade") == 0 &&
- os_strcmp (pURL_Frame->pCommand, "command") == 0)
+ else
+ if (os_strcmp (pURL_Frame->pSelect, "upgrade") == 0 &&
+ os_strcmp (pURL_Frame->pCommand, "command") == 0)
{
if (os_strcmp (pURL_Frame->pFilename, "getuser") == 0)
{
@@ -2140,18 +2122,15 @@ webserver_recv (void *arg, char *pusrdata, unsigned short length)
}
break;
-
case POST:
os_printf ("We have a POST request.\n");
pParseBuffer = (char *) os_strstr (precvbuffer, "\r\n\r\n");
-
if (pParseBuffer == NULL)
{
break;
}
pParseBuffer += 4;
-
if (os_strcmp (pURL_Frame->pSelect, "config") == 0 &&
os_strcmp (pURL_Frame->pCommand, "command") == 0)
{
@@ -2184,7 +2163,6 @@ webserver_recv (void *arg, char *pusrdata, unsigned short length)
#else
rstparm->parmtype = REBOOT;
#endif
-
if (restart_10ms == NULL)
{
restart_10ms =
@@ -2195,7 +2173,6 @@ webserver_recv (void *arg, char *pusrdata, unsigned short length)
(os_timer_func_t *) restart_10ms_cb,
NULL);
os_timer_arm (restart_10ms, 10, 0); // delay 10ms, then do
-
response_send (ptrespconn, true);
}
else
@@ -2210,7 +2187,6 @@ webserver_recv (void *arg, char *pusrdata, unsigned short length)
struct jsontree_context js;
user_esp_platform_set_connect_status
(DEVICE_CONNECTING);
-
if (restart_10ms != NULL)
{
os_timer_disarm (restart_10ms);
@@ -2234,7 +2210,6 @@ webserver_recv (void *arg, char *pusrdata, unsigned short length)
(struct jsontree_value *)
&wifi_req_tree, json_putchar);
json_parse (&js, pParseBuffer);
-
if (rstparm == NULL)
{
rstparm =
@@ -2243,13 +2218,11 @@ webserver_recv (void *arg, char *pusrdata, unsigned short length)
rstparm->pespconn = ptrespconn;
rstparm->parmtype = WIFI;
-
if (sta_conf->ssid[0] != 0x00
|| ap_conf->ssid[0] != 0x00)
{
ap_conf->ssid_hidden = 0;
ap_conf->max_connection = 4;
-
if (restart_10ms == NULL)
{
restart_10ms =
@@ -2307,11 +2280,9 @@ webserver_recv (void *arg, char *pusrdata, unsigned short length)
if (pParseBuffer != NULL)
{
struct jsontree_context js;
-
jsontree_setup (&js, (struct jsontree_value *) &PwmTree,
json_putchar);
json_parse (&js, pParseBuffer);
-
os_printf ("rsp1:%u\n", PostCmdNeeRsp);
if (PostCmdNeeRsp == 0)
PostCmdNeeRsp = 1;
@@ -2331,7 +2302,6 @@ webserver_recv (void *arg, char *pusrdata, unsigned short length)
system_param_save_with_protect (ESP_PARAM_START_SEC,
&esp_param,
sizeof (esp_param));
-
system_restore ();
system_restart ();
}
@@ -2342,8 +2312,9 @@ webserver_recv (void *arg, char *pusrdata, unsigned short length)
response_send (ptrespconn, false);
}
}
- else if (os_strcmp (pURL_Frame->pSelect, "upgrade") == 0 &&
- os_strcmp (pURL_Frame->pCommand, "command") == 0)
+ else
+ if (os_strcmp (pURL_Frame->pSelect, "upgrade") == 0 &&
+ os_strcmp (pURL_Frame->pCommand, "command") == 0)
{
if (os_strcmp (pURL_Frame->pFilename, "start") == 0)
{
@@ -2410,13 +2381,13 @@ static ICACHE_FLASH_ATTR void
webserver_recon (void *arg, sint8 err)
{
struct espconn *pesp_conn = arg;
-
- os_printf ("webserver's %d.%d.%d.%d:%d err %d reconnect\n",
- pesp_conn->proto.tcp->remote_ip[0],
- pesp_conn->proto.tcp->remote_ip[1],
- pesp_conn->proto.tcp->remote_ip[2],
- pesp_conn->proto.tcp->remote_ip[3],
- pesp_conn->proto.tcp->remote_port, err);
+ os_printf
+ ("webserver's %d.%d.%d.%d:%d err %d reconnect\n",
+ pesp_conn->proto.tcp->remote_ip[0],
+ pesp_conn->proto.tcp->remote_ip[1],
+ pesp_conn->proto.tcp->remote_ip[2],
+ pesp_conn->proto.tcp->remote_ip[3],
+ pesp_conn->proto.tcp->remote_port, err);
}
/******************************************************************************
@@ -2429,7 +2400,6 @@ static ICACHE_FLASH_ATTR void
webserver_discon (void *arg)
{
struct espconn *pesp_conn = arg;
-
os_printf ("webserver's %d.%d.%d.%d:%d disconnect\n",
pesp_conn->proto.tcp->remote_ip[0],
pesp_conn->proto.tcp->remote_ip[1],
@@ -2448,7 +2418,6 @@ static void ICACHE_FLASH_ATTR
webserver_listen (void *arg)
{
struct espconn *pesp_conn = arg;
-
espconn_regist_recvcb (pesp_conn, webserver_recv);
espconn_regist_reconcb (pesp_conn, webserver_recon);
espconn_regist_disconcb (pesp_conn, webserver_discon);
diff --git a/polycom_xmit/wifi.c b/polycom_xmit/wifi.c
index c094355..0b2c725 100644
--- a/polycom_xmit/wifi.c
+++ b/polycom_xmit/wifi.c
@@ -10,9 +10,12 @@ wifi_init (void)
wifi_station_set_config_current (&config);
wifi_set_opmode_current (STATION_MODE);
+ wifi_set_phy_mode (PHY_MODE_11N);
wifi_station_set_reconnect_policy (true);
-
+
+ wifi_station_set_auto_connect (true);
+
//wifi_station_connect();
//wifi_station_dhcpc_start ();
}