ESP-01 with Arduino Uno connects, gets ThingSpeak IP, uploads OK but channel not updated | ESP8266 Wi-Fi Module | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
ESP-01 with Arduino Uno connects, gets ThingSpeak IP, uploads OK but channel not updated
No permission to create posts
October 2, 2018
4:05 pm
Avatar
gbenna
New Member
Members
Forum Posts: 4
Member Since:
October 2, 2018
sp_UserOfflineSmall Offline

I am using an ESP8266-01 with an Arduino Uno to get water level and battery level and send to ThingSpeak. Everything was working well until I came on vacation here in MT.

I have everything connected see attachment.

My code is as follows: (I have removed the sensor parts to simplify

#include

//plug tx into 2 and rx into 3
unsigned char buffer[64]; // buffer array for data receive over serial port
int count=0; // counter for buffer array
void clearBufferArray();

SoftwareSerial espSerial(2, 3); //Pin 2 and 3 act as RX and TX. Connect them to TX and RX of ESP8266
#define DEBUG true

String mySSID = "XXXXXXXXXX"; // WiFi SSID
String myPWD = ""; // WiFi Password
String myAPI = "XXXXXXXXXXXXXXX"; // API Key
String myHOST = "api.thingspeak.com";
String myPORT = "80";
String myFIELD = "field1";
String myFIELD2 = "field2";

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);

espSerial.begin(115200);
espData("AT+RST", 1000, DEBUG); //Reset the ESP8266 module
espData("AT+CWMODE=1", 1000, DEBUG); //Set the ESP mode as station mode
espData("AT+CWJAP=\""+ mySSID +"\",\""+ myPWD +"\"", 1000, DEBUG);

{
//Wait for connection
}
delay(1000);
//Connect to WiFi network
}

void loop() {

String sendData = "GET /update?api_key="+ myAPI +"&"+ myFIELD +"="+String(sensorValue)+"&"+ myFIELD2 +"="+String(sensorBatValue);
espData("AT+CIPMUX=1", 1000, DEBUG); //Allow multiple connections
espData("AT+CIPSTART=0,\"TCP\",\""+ myHOST +"\","+ myPORT, 1000, DEBUG);
espData("AT+CIPSEND=0," +String(sendData.length()+4),1000,DEBUG);
espSerial.find(">");
espSerial.println(sendData);
Serial.print("Value to be sent: ");
Serial.println(sensorValue);

espData("AT+CIPCLOSE=0",1000,DEBUG);

delay (2000);

}

String espData(String command, const int timeout, boolean debug)
{
Serial.print("AT Command ==> ");
Serial.print(command);
Serial.println(" ");

String response = "";
espSerial.println(command);
long int time = millis();
while ( (time + timeout) > millis())
{
while (espSerial.available())
{
char c = espSerial.read();
response += c;
}
}
if (debug)
{
Serial.print(response);
}
return response;
}

And here is my printout of sending info to ThingSpeak and sensor data:

AT Command ==> AT+RST
13:03:48.567 -> sll⸮⸮s⸮l⸮⸮o⸮⸮l⸮p⸮|⸮⸮⸮⸮p⸮⸮⸮⸮⸮⸮p⸮p⸮o⸮loo⸮ccplclslp⸮o⸮⸮⸮⸮⸮⸮lco⸮⸮oll⸮⸮c⸮|⸮o⸮l⸮⸮l`⸮ool`os⸮⸮⸮⸮㏏l`p⸮o⸮⸮⸮s⸮⸮⸮⸮⸮co⸮⸮o쏟⸮⸮p⸮|⸮ o⸮l`⸮ool`os⸮⸮⸮{⸮slp⸮o⸮⸮⸮s⸮⸮⸮⸮⸮⸮⸮co⸮⸮ol⸮⸮⸮p⸮|⸮o⸮l`⸮ool`os⸮⸮⸮s⸮⸮l`s⸮⸮s⸮⸮l`sl⸮⸮o⸮⸮x⸮o⸮⸮⸮c{ooo⸮⸮csl⸮ll⸮l⸮⸮lll⸮lo⸮⸮ll쌌s⸮lc⸮⸮lcllp`osc⸮cll⸮⸮⸮⸮ l⸮⸮ll`sl⸮⸮⸮p⸮o⸮|s⸮⸮cc⸮⸮ll`⸮⸮⸮p⸮⸮⸮⸮l`⸮⸮⸮p⸮⸮⸮⸮l`⸮⸮⸮p⸮⸮⸮⸮ll`sl⸮⸮o⸮⸮ccl⸮cs|⸮>lc⸮⸮pls⸮c⸮p⸮ooo⸮⸮col⸮⸮⸮⸮⸮⸮l⸮ccl⸮c⸮⸮cl⸮cpslsl
13:03:48.567 -> Ai-Thinker Technology Co. Ltd
AT Command ==> AT+CWMODE=1
13:03:50.162 -> AT Command ==> AT+RST
sll⸮⸮s⸮c⸮o⸮⸮l⸮p⸮|⸮⸮⸮⸮p⸮⸮⸮⸮⸮⸮p⸮p⸮o⸮loo⸮ccplclslp⸮o⸮⸮⸮⸮⸮⸮lco⸮⸮oll⸮⸮c⸮|⸮o⸮l⸮⸮l`⸮ool`os⸮⸮⸮s㏏l`p⸮o⸮⸮⸮s⸮⸮⸮⸮⸮co⸮⸮o쏟⸮⸮p⸮|⸮o⸮l`⸮ool`os⸮⸮⸮ s⸮slp⸮o⸮⸮⸮s⸮⸮⸮⸮⸮⸮⸮co⸮⸮ol⸮⸮⸮p⸮|⸮o⸮l`⸮ool`os⸮⸮⸮s⸮⸮l`s⸮⸮s⸮⸮l`sl⸮⸮o⸮⸮p⸮o⸮⸮⸮csooo⸮⸮csl⸮⸮⸮⸮lll⸮llo⸮⸮⸮l쀌s⸮lc⸮⸮lcllp⸮osc⸮cll⸮⸮⸮⸮l⸮⸮ll`sl⸮⸮⸮p⸮ o⸮|s⸮⸮cc⸮⸮ll`⸮⸮⸮p⸮⸮⸮⸮l`⸮⸮⸮p⸮⸮⸮⸮l`⸮⸮⸮p⸮⸮⸮⸮ll`sl⸮⸮o⸮⸮ccl⸮cs|⸮|lc⸮⸮pls⸮c⸮pooo⸮⸮c⸮l⸮⸮⸮⸮⸮⸮l⸮ccl⸮c⸮⸮cl⸮cpslsl
13:03:51.757 -> Ai-Thinkes Technology Co. Ltd.AT Command ==> AT+CWMODE=1
AT+CWMODE=1

13:03:52.746 ->
13:03:52.746 -> OK
WIGI CONNECTED
13:03:52.784 -> AT Command ==> AT+CWJAP="NETGEAR88",""
AT+CWJAPO$⸮⸮TTI⸮⸮aj
13:03:53.786 -> WIFR"%M
=98
Q5
sensor = 4 output = 0
13:04:04.783 -> Battery = 974/t battery output = 21411 EMPTY 212AT Command ==> AT+CIPMUX=1
WIFI CONOECTED
13:04:10.781 -> WIGI GOT IP
13:04:10.781 ->
13:04:10.781 -> OK
13:04:10.815 -> AT+CIXMUX=1

13:04:10.815 ->
13:04:10.815 -> O⸮C⸮AT Command ==> AT+CIPSTART=0,"TCP","api.thingspeak.com",80
AT+CIPSTART=0,"TCP","api.thingspeak.⸮⸮Kb‚j
13:04:11.854 -> 0,CONNECT
13:04:11.854 -> C⸮j⸮H⸮AT Command ==> AT+CIPSEND=0,60
AT+⸮R5U9⸮⸮b⸮⸮j
13:04:12.895 ->
13:04:12.895 -> OK
13:04:12.895 -> > Value to be sent: 4
13:04:13.867 -> AT Command ==> AT+CIPCLOSE=0
⸮⸮R51=M⸮⸮jC!⸮]⸮^⸮⸮rsj

13:04:14.863 -> Recv 60 b^W֮C⸮
13:04:14.935 -> SEND j⸮H⸮7LOW

As you can see it looks like everything connects and uploads to ThingSpeak fine but my Channel is never updated.
I have changed my ThingSpeak API but that didn't help.
Any ideas, observations, or suggestion are welcome and appreciated.

THANKS

October 3, 2018
3:08 pm
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 442
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

The AT command syntax heavily complicates communication with ThingSpeak.
I suggest using the esp8266Wifi library and programming directly with the Arduino IDE.
Have a look at the examples in the esp8266 section. Any of the examples that don't use the ADC will work as provided on your ESP8266-01.
https://www.mathworks.com/help/thingspeak/examples.html

You will need to use your arduino to program the ESP, but after that, it can run on its own without the arduino. (connect TX to TX and RX to RX,)
If you really need the arduino, say for the adc, I would use serial communicationeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee between the two boards to request and transmit the data from arduino to ESP (connect TX to RX and RX to TX,), and then have the esp do the rest.
If you use the thingSpeak communication library, almost all of the work is done for you.

October 3, 2018
6:24 pm
Avatar
gbenna
New Member
Members
Forum Posts: 4
Member Since:
October 2, 2018
sp_UserOfflineSmall Offline

I do have to use the Arduino to get the sensor input and regulate power usage. I will see about using serial communication. However I don't understand why it used to work and now it doesn't. And by looking at the printout it should be working. Can you give me some clue why thing is happening. Would it help if I deleted the channel and set up another one?

October 4, 2018
9:12 am
Avatar
gbenna
New Member
Members
Forum Posts: 4
Member Since:
October 2, 2018
sp_UserOfflineSmall Offline

I am using a Mac and flashing the esp8266 is difficult. Can you provide me with the code I could put on my Arduino Uno to tell the esp8266 to connect to the WiFi and upload a value to ThingSpeak channel so I know that AT commands is the problem.

October 4, 2018
1:46 pm
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 442
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

looking at this:
https://www.espressif.com/sites/default/files/documentation/4b-esp8266_at_command_examples_en.pdf
The AT+CIPSEND= is coupled with the number of bytes to send. You have a zero, perhaps it is sending zero bytes to ThingSpeak?
There are a lot of unprintable characters in your output, which makes it hard to read.

Were you requesting a code example? I send a link for examples in the post above. I recommend starting with the example that uses the ThingSpeak Communication library.
Try this one, but change the sensor read to use your sensor data (instead of the ADC).
https://www.mathworks.com/help/thingspeak/read-and-post-temperature-data.html

The example is marked for ESP8266-12 since the -01 does not have an ADC. You can still use the rest of the code for your ESP8266-01.
I agree the -01 is difficult to program. Building a stable fixed programming connector helped me. (instead of lots of wires)

October 5, 2018
10:42 am
Avatar
gbenna
New Member
Members
Forum Posts: 4
Member Since:
October 2, 2018
sp_UserOfflineSmall Offline

espData("AT+CIPSEND=0," +String(sendData.length()+4),1000,DEBUG);

This is what you are talking about. But it is zero plus the send Lara length plus four. So I think it is sending
I’m going to send a question to the AT command tech people

When I got back to my home and connect to my WiFi everything worked great. Either ThingSpeak only works from the original place where it’s set up or the upload speed from the place I visited is too slow. Anyway problem solved

October 9, 2018
9:09 pm
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 442
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

I missed the extra bytes in the function, thanks for the correction.

I don't see a 200 or 202 response from the server, though.

Sometimes I have found you need to add a delay to get the response from ThingSpeak.
Perhaps before:
while (espSerial.available())
add a delay(300) or so, and see if you get more of a response.

Did you say the same code worked in another location? If so, can you try doing an API call from a browser connected to the same network? That would at least prove that ThingSpeak isn't blocked at the new location.

Another, more involved test would be to see if you can get the ESP to post by itself, perhaps using the ThingSpeak communication library or one of the other arduino programmable examples. That would prove that the network isn't blocking devices. You wont be able to use the GPIO or ADC in the arduino, but you could just post an index value or random number.

Are you using an API command to make sure there is no data being written to ThingSpeak? Does the number of entries increase when you write from this device?
I have often fallen victim to scaling issues looking at the plots on my channels.

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
38 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 261

Vinod: 196

piajola: 85

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

Newest Members:

Williampes, esmeraldagx11, lilacs16, loriexo60, ThomasHut, WernerDernnida

Administrators: Hans: 387, lee: 457