thingspeak with new sdk
Posted: Sat Jan 31, 2015 4:49 am
i am trying to post data to thingspeak with new at example from 0.9.5 sdk and i didnt make it work. the code working with my local server but it seems something wrong with my request so thingspeak loging not working. here is code.
i tried on sockettest3 and i connect thingspeak with this ip and just send "GET /update?key=mykey&field1=9" and its updating. so i wrote this code. anyone have any idea?
also i tried this code with host and other parameters but its not working too.(with os_delay and without os_delay not working.)
i tried on sockettest3 and i connect thingspeak with this ip and just send "GET /update?key=mykey&field1=9" and its updating. so i wrote this code. anyone have any idea?
Code: Select all
#define TCPSERVERIP "184.106.153.149"
#define TCPSERVERPORT 80
static void ICACHE_FLASH_ATTR
at_tcpclient_connect_cb(void *arg)
{
struct espconn *pespconn = (struct espconn *)arg;
#ifdef PLATFORM_DEBUG
at_port_print("TCP client connect\r\n");
#endif
espconn_regist_sentcb(pespconn, at_tcpclient_sent_cb);
//espconn_regist_recvcb(pespconn, at_tcpclient_recv);
espconn_regist_disconcb(pespconn, at_tcpclient_discon_cb);
char payload[128];
//1
os_sprintf(payload,"GET /update?key=mykey&field1=9");
#ifdef PLATFORM_DEBUG
at_port_print(payload);
#endif
espconn_sent(pespconn, payload, strlen(payload));
}
also i tried this code with host and other parameters but its not working too.(with os_delay and without os_delay not working.)
Code: Select all
static void ICACHE_FLASH_ATTR
at_tcpclient_connect_cb(void *arg)
{
struct espconn *pespconn = (struct espconn *)arg;
#ifdef PLATFORM_DEBUG
at_port_print("TCP client connect\r\n");
#endif
espconn_regist_sentcb(pespconn, at_tcpclient_sent_cb);
//espconn_regist_recvcb(pespconn, at_tcpclient_recv);
espconn_regist_disconcb(pespconn, at_tcpclient_discon_cb);
char payload[128];
//1
os_sprintf(payload,"GET /update?key=mykey&field1=9 HTTP/1.1\r\n");
#ifdef PLATFORM_DEBUG
at_port_print(payload);
#endif
espconn_sent(pespconn, payload, strlen(payload));
os_delay_us(500*1000);
//2
os_sprintf(payload,"Host: api.thingspeak.com\r\n");
#ifdef PLATFORM_DEBUG
at_port_print(payload);
#endif
espconn_sent(pespconn, payload, strlen(payload));
os_delay_us(500*1000);
//3
os_sprintf(payload,"Accept: */*\r\n");
#ifdef PLATFORM_DEBUG
at_port_print(payload);
#endif
espconn_sent(pespconn, payload, strlen(payload));
os_delay_us(500*1000);
//4
os_sprintf(payload,"User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n");
#ifdef PLATFORM_DEBUG
at_port_print(payload);
#endif
espconn_sent(pespconn, payload, strlen(payload));
os_delay_us(500*1000);
//5
os_sprintf(payload,"\r\n");
#ifdef PLATFORM_DEBUG
at_port_print(payload);
#endif
espconn_sent(pespconn, payload, strlen(payload));
os_delay_us(500*1000);
}