Sending data to thingspeak problem | ThingSpeak API | 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
Sending data to thingspeak problem
No permission to create posts
January 25, 2017
7:04 pm
Avatar
Rist
New Member
Members
Forum Posts: 1
Member Since:
January 25, 2017
sp_UserOfflineSmall Offline

Hello thingspeak community,
Im pretty new with arduino, esp8266, and thingspeak. I made a simple program that should send data to thingspeak and it worked yesterday. I can see the data on the thingspeak page. However, I tried to run the program again today but, nothing showed up on thingspeak. I tried to web this http://184.106.153.149/update?api_key=XXX&field1=255 and it works. Is there something wrong with my code? Any help and suggestion will be really helpful. Thank you. This is the program I made:

#include

SoftwareSerial wifi(10, 11);

String network = "Bali_Nine";
String password = "password";
#define IP "184.106.153.149"
String GET = "GET /update?api_key=XXX";

void setup()
{  
  Serial.begin(9600);
  wifi.begin(9600);
  wifi.println("AT+RST");
  delay(2000);
}

void loop()
{
  wifisetup();
  int sensordata = 159;
  updateTemp(String(sensordata));  
  delay(2000);
}

void wifisetup()
{
  Serial.println("Checking WiFi module");
  wifi.println("AT");
  if(wifi.find("OK"))
  {
    Serial.println("Found OK");
    connectToWifi();
  }
  else
  {
    Serial.println("OK not found");
  }
  delay(2000);
}

bool connectToWifi()
{
  Serial.println("Connecting to WiFi");
  wifi.println("AT+CWJAP?");
  if(wifi.find("ERROR"))
  {   
    String cmd = "AT+CWJAP=\"";
    cmd += network;
    cmd += "\",\"";
    cmd += password;
    cmd += "\"";
    Serial.println(cmd);
    wifi.println(cmd);
    delay(2000);
    if(wifi.find("OK"))
    {
      Serial.println("OK, Connected to WiFi");    
      return true;
    }
    else
    {
      Serial.println("Can't connect to WiFi");
      return false;
    }
  }
  else
  {
    Serial.println("OK, Connected to WiFi");
    return true;
  }
}

void updateTemp(String voltage1)
{
  Serial.println("Sending data");
  String cmd = "AT+CIPSTART=\"TCP\",\"";
  cmd += IP;
  cmd += "\",80";
  wifi.println(cmd);
  Serial.println(cmd);
  delay(5000);
  if(wifi.find("ERROR"))
  {
    Serial.println("Error while sending");
    return;
  }
  cmd = GET+"&field1="+voltage1+"
";
  wifi.print("AT+CIPSEND=");
  wifi.println(cmd.length());
  delay(20000);
  if(wifi.find(">"))
  {
    wifi.print(cmd);
    Serial.println(cmd);
    Serial.println("Data sent");
  }
  else
  {
    wifi.println("AT+CIPCLOSE");
    Serial.println("Connection closed");
  }
}

January 26, 2017
4:38 pm
Avatar
piajola

Gold
Members
Forum Posts: 113
Member Since:
October 12, 2015
sp_UserOfflineSmall Offline

Hi Rist,

I am doing the same arduino+ESP8266 (AT way) until now 451000+ points in TS - it works and for less than $10

1 tried via browser (you too)
2 tried directly with ESP8266 via RS232 with Termite (same as arduino monitor) typing AT commands and waiting answers then check the plot in my TS channel
3 writing the arduino program to plot fully automatic

What I did for point 2

 

-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
AT+GMR
AT version:0.50.0.0(Sep 18 2015 20:55:38)
SDK version:1.4.0
compile time:Sep 18 2015 21:32:07
OK
------------------------------------------
AT+CWMODE?
+CWMODE:3
OK
------------------------------------------
AT+CIPMODE?
+CIPMODE:0
OK
------------------------------------------
AT+CIPMUX?
+CIPMUX:0
OK
------------------------------------------
AT+CIPSTATUS
STATUS:2
OK
------------------------------------------
AT+CIPSTART="TCP","api.thingspeak.com",80
CONNECT
OK
------------------------------------------
AT+CIPSEND=64
OK
>
------------------------------------------
GET /update?api_key=sixteenUPlowcase&field1=25.12&field2=55.31 << count 1 space after GET before slash totaling 62 plus [newline][return]=64
Recv 64 bytes
SEND OK
+IPD,5:12825CLOSED      << 3 lines TS say it was fine
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
Note when I did
------------------------------------------
AT+CIPSTART="TCP","184.105.153.149",80
ERROR
CLOSED
------------------------------------------
it DID NOT worked!! (I do not know why ... IP?)

Count spaces and follow UPPER/lower case ... (use non proportional fonts I use Notepad with CONSOLAS font to SEE spaces)

I did this a few times for 2 days ... just in casw

I did not checked carefully your program but in loop you are using 2 seconds not the 15 minimum  I use 1 minute (Good to me)

I tried at least 2 versions of firmware and syntaxis varied slightly. i.e. AT+CIPSTART answer ERROR and Error so arduino gets confused

Can you post your serial output?

November 2, 2018
2:10 pm
Avatar
CuteGolem
New Member
Members
Forum Posts: 2
Member Since:
November 2, 2018
sp_UserOfflineSmall Offline

Hey piajola
Can u send the code that u have done
AT+CIPSTART="TCP","api.thingspeak.com",80

this line in my program doesnt works but when i input directly it works
U said ur code worked may some format of u code is correct
So pls send the code

THANKS

July 15, 2020
4:33 pm
Avatar
R.Colombo
New Member
Members
Forum Posts: 1
Member Since:
July 15, 2020
sp_UserOfflineSmall Offline

Hi Rist,
Have you solved the problem?
the data string must be escaped at the end (= chr (26)
Example: The string below it has the size = 95
Then, the command AT + CIPSEND = 97 (string size + 2)
otherwise, chr (26) is not read in Thingspeak

string="GET https://api.thingspeak.com/update?api_key=xxxxxxxxxxxx&field1=" + str(xxx) +"&field2="+ str(xxx) + chr(26)

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
7 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:

khanhNguyen_CT, susyburr, quijano__, meosuckhoe, briskpanda, Dejw0089

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457