Chat freely about anything...

User avatar
By alonewolfx2
#8580 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?
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 allstatic 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);
}
User avatar
By alonewolfx2
#8832 which sdk you are using?
piontec wrote:ThingSpeak worked like a charm for me, see here: https://github.com/piontec/esp_rest/blob/master/user/user_main.c#L111, but it was when my esp could get an IP from the server ;)