Sensor data not uploading to thingspeakchannel but it show on the serial monitor | Arduino | 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
Sensor data not uploading to thingspeakchannel but it show on the serial monitor
No permission to create posts
February 16, 2018
4:45 am
Avatar
deokumardas
New Member
Members
Forum Posts: 3
Member Since:
February 15, 2018
sp_UserOfflineSmall Offline

Your help will be appreciated.

Thanks in advance.

I tried to send soil moisture data on the thingspeak channel but I didn't. The code is given below

#include <SoftwareSerial.h>
#include <ThingSpeak.h>
#include <stdlib.h>
String apikey="X";      // write api key of the channel
#define ssid "connectify"
#define PASS "1234567890"
SoftwareSerial softser(11,10); // Rx connected at digitalpin 10 and tx at 11

void setup()
{
delay(2000);

Serial.begin(9600);
softser.begin(9600);
softser.println("AT+RST");
}
void loop()
{
String join="AT+CWJAP=\"";
join+=ssid;
join+="\",\"";
join+=PASS;
join+="\"";
softser.println(join);

delay(5000);
float val=analogRead(A0); // Soil moisture sensor reading
float t=val*5.0f/1023.0f;
char buf[16];
String strtemp=dtostrf(t,4,1,buf);
Serial.println(strtemp);
String cmd="AT+CIPSTART=\"TCP\",\"";
cmd+="184.106.153.149";
cmd+="\",80";
softser.println(cmd);

if(softser.find("Error"))
{
Serial.println("AT+CIPSTART error ");
return;
}
String getstr="GET https://api.thingspeak.com/update?api_key=";
getstr+=apikey;
getstr+="&field1=";

getstr+=String(strtemp);

getstr+="

";
Serial.println(getstr);
cmd="AT+CIPSEND=";
cmd+=String(getstr.length());
softser.println(cmd);

if (softser.find(">"))
{
softser.print(getstr);
}
else
{
softser.println("AT+CIPCLOSE");
Serial.println("AT+CIPCLOSE");
}
softser.println("AT+RST");
delay(20000);
}

February 16, 2018
8:48 am
Avatar
cstapels
Moderator
Members


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

Looks like a good start.  Lets eliminate the easy things.  If you use your web browser and the REST command to Write Data, can you successfully update the channel?

i.e. paste this in the address bar : https://api.thingspeak.com/update?api_key=XXXXXXXXXXXXXXXX&field1=321

 

Does your hardware indicate that it is connecting to the network appropriately?

If all that works, can you try hard coding this line

String getstr="GET https://api.thingspeak.com/update?api_key=";

to the full command

String getstr="GET https://api.thingspeak.com/update?api_key=XXXXXXXXXXXXXXXX&field1=123";

(replacing your API key, of course)

Then see if 123 gets populated to the channel from the device.

If all that is successful, please describe your hardware and we can scrutinize the code closer.

February 16, 2018
11:05 am
Avatar
deokumardas
New Member
Members
Forum Posts: 3
Member Since:
February 15, 2018
sp_UserOfflineSmall Offline

By pasting in the address bar, the channel is updated with the given value.

I tried with this  (String getstr="GET https://api.thingspeak.com/update?api_key=XXXXXXXXXXXXXXXX&field1=123";) by replaying "X" with apikey but problem still exist.

The hardware connection is shown in the image file and drive link is shared below.

https://drive.google.com/open?id=1lc2zRm9XzDiKnCgULxWRA5-mmxSXNSd0

 

How to test whether the hardware is connected to a network or not?

February 16, 2018
2:43 pm
Avatar
cstapels
Moderator
Members


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

From your drawing it seems the you are using an ESP8266-01, connected to an Arduino.  If this is true, there is a much easier was to interact with the esp than the AT command set.  You can use the Arduino IDE to program the ESP directly.  Some people say there is an incompatibility with the 5 V outputs, but I have programmed many ESP8266-01 and found them to be 5 V tolerant for the TX and RX pins (not for VDD).  Most of the Arduino examples in the examples section of the ThingSpeak doc will work with small changes, and there are a few ESP8266 specific examples  for reading and writing data with and without the ThingSpeak communication library. 

Connect TX and RX straight into the TX and RX from the Arduino, pull up GPIO2 and CH_PD (and possibly RST), and pull GPIO0 to ground when programming.

If I am wrong about the hardware, then we can stick to the AT commands. I think if you had a connection error, you would have seen it with these lines:

if(softser.find("Error"))
{
Serial.println("AT+CIPSTART error ");

Can you share what you see on the serial monitor?

February 17, 2018
5:28 am
Avatar
deokumardas
New Member
Members
Forum Posts: 3
Member Since:
February 15, 2018
sp_UserOfflineSmall Offline

Serial monitor output is shown via link below:

https://drive.google.com/open?id=1h7BNDskQYVlEMDmMAgBo6lGTG4F7KrVo

 

since esp8266 has three modes of operation: Access point,STA, both

in order to send data , esp8266 should remain in STA mode or something else. I fix mode at STA mode using AT+CWMODE=1 command.

If I am wrong, please do correct me

February 20, 2018
4:22 pm
Avatar
cstapels
Moderator
Members


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

In this example code, they do not include the server name in the GET string.  I would not suggest using software serial as they do in that example, I have seen issues with software serial on ESP8266-01 (possibly due to not shifting the voltage).

...String getStr = "GET /update?api_key=";..

Also, they include some carriage returns that your code does not seem to have. 

... getStr += "

";...

Is there a reason you need to use the AT commands instead of programming the ESP to do the communication itself?

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
19 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 272

Vinod: 240

piajola: 95

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 8665

Moderators: 1

Admins: 2

Forum Stats:

Groups: 3

Forums: 14

Topics: 1600

Posts: 5760

Newest Members:

qkpham, SANGAMNATH B, swatiiot, kalyanigaware16@gmail.com, Romi, Drakan01

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457