ESP01S IoT – Thingspeak GET submission

ESP01S first experience outlined steps to get a ESP01S up and running.

This article lays out an example IoT submission to Thingspeak using Expect as the test frame.

The expect script follows. The script shows the AT commands to connect to an access point, start a TCP session with the Thingspeak host, and submit a GET request with the telemetry data. Note that the Thingspeak host is specified by IP address, there is no DNS support available.

set timeout 10
#flush buffer
expect -re $
send "AT\r\n"
expect "OK"
send "AT+GMR\r\n"
expect "OK"
send "AT+CWMODE=1\r\n"
expect "OK"
send "AT+CWJAP=\"ssid\",\"pwd\"\r\n"
expect "OK"
send "AT+CIFSR\r\n"
expect "OK"
send "AT+CIPSTART=\"TCP\",\"52.22.86.23\",80\r\n"
expect "OK"
send "AT+CIPSEND=64\r\n"
expect "OK"
send "GET /update?api_key=apikey&field1=21.2&field2=35.6\r\n\r\n"
expect "OK"
expect {
  "CLOSED" {
    }
  timeout {
    send_log $expect_out(buffer)
    }
  }

Below is the log file from the expect script run.

spawn [open ...]
AT
OK
AT+GMR
AT version:1.6.2.0(Apr 13 2018 11:10:59)
SDK version:2.2.1(6ab97e9)
compile time:Jun  7 2018 19:34:26
Bin version(Wroom 02):1.6.2
OK
AT+CWMODE=1
OK
AT+CWJAP="ssid","pwd"
WIFI DISCONNECT
WIFI CONNECTED
WIFI GOT IP
OK
AT+CIFSR
+CIFSR:STAIP,"192.168.0.99"
+CIFSR:STAMAC,"a4:cf:12:b9:80:27"
OK
AT+CIPSTART="TCP","52.22.86.23",80
CONNECT
OK
AT+CIPSEND=64
OK
> 
Recv 64 bytes
SEND OK
+IPD,5:12828CLOSED

The final response is the record number of the record accepted by Thingspeak and then the TCP session is closed.

An arduino implementation will take some code to wait for expected responses, handle responses and exceptions… but this example shows the ‘conversation’.