Two values to thingspeak server | ThingSpeak API | Forum

Avatar

Please consider registering
Guest

Search

— Forum Scope —






— Match —





— Forum Options —





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

Register Lost password?
sp_Feed sp_TopicIcon
Two values to thingspeak server
Avatar
MURLIDHAR ROY
New Member
Forum Posts: 3
sp_UserOfflineSmall Offline
1
January 3, 2018 - 3:33 pm
sp_Permalink sp_Print

I am trying to send two sensor data to thingspeak. Please tell me how to write command to send two sensor data. The basic program which I am using is given below.

 

#include <SoftwareSerial.h>
/* Create object named SIM900 of the class SoftwareSerial */
SoftwareSerial SIM900(8, 7);
void setup()
{
SIM900.begin(9600); /* Define baud rate for software serial communication */
Serial.begin(9600); /* Define baud rate for serial communication */
}

void loop() {
Serial.println("HTTP post method :");
Serial.print("AT\
\
");
SIM900.println("AT"); /* Check Communication */
delay(500);
ShowSerialData(); /* Print response on the serial monitor */
delay(500);
/* Configure bearer profile 1 */
Serial.print("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"\
\
");
SIM900.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\""); /* Connection type GPRS */
delay(500);
ShowSerialData();
delay(500);
Serial.print("AT+SAPBR=3,1,\"APN\",\"airtelgprs.com\"\
\
");
SIM900.println("AT+SAPBR=3,1,\"APN\",\"airtelgprs.com\""); /* APN of the provider */
delay(500);
ShowSerialData();
delay(500);
Serial.print("AT+SAPBR=1,1\
\
");
SIM900.println("AT+SAPBR=1,1"); /* Open GPRS context */
delay(500);
ShowSerialData();
delay(500);
Serial.print("AT+SAPBR=2,1\
\
");
SIM900.println("AT+SAPBR=2,1"); /* Query the GPRS context */
delay(500);
ShowSerialData();
delay(2000);
Serial.print("AT+HTTPINIT\
\
");
SIM900.println("AT+HTTPINIT"); /* Initialize HTTP service */
delay(2000);
ShowSerialData();
delay(500);
Serial.print("AT+HTTPPARA=\"CID\",1\
\
");
SIM900.println("AT+HTTPPARA=\"CID\",1"); /* Set parameters for HTTP session */
delay(500);
ShowSerialData();
delay(500);
Serial.print("AT+HTTPPARA=\"URL\",\"api.thingspeak.com/update\"\
\
");
SIM900.println("AT+HTTPPARA=\"URL\",\"api.thingspeak.com/update\""); /* Set parameters for HTTP session */
delay(500);
ShowSerialData();
delay(500);
Serial.print("AT+HTTPDATA=33,10000\
\
");
SIM900.println("AT+HTTPDATA=33,10000"); /* POST data of size 33 Bytes with maximum latency time of 10seconds for inputting the data*/
delay(200);
ShowSerialData();
delay(200);
Serial.print("api_key=8MMR5DD7QC42NAUJ&field1=2\
\
"); /* Data to be sent */
SIM900.println("api_key=8MMR5DD7QC42NAUJ&field1=2");
delay(500);
ShowSerialData();
delay(500);
Serial.print("AT+HTTPACTION=1\
\
");
SIM900.println("AT+HTTPACTION=1"); /* Start POST session */
delay(1000);
ShowSerialData();
delay(2000);
Serial.print("AT+HTTPTERM\
\
");
SIM900.println("AT+HTTPTERM"); /* Terminate HTTP service */
delay(2000);
ShowSerialData();
delay(500);
Serial.print("AT+SAPBR=0,1\
\
");
SIM900.println("AT+SAPBR=0,1"); /* Close GPRS context */
delay(500);
ShowSerialData();
delay(500);
}

void ShowSerialData()
{
while(SIM900.available()!=0) /* If data is available on serial port */
Serial.write(char (SIM900.read())); /* Print character received on to the serial monitor */
}

Avatar
cstapels

Gold
Forum Posts: 123
sp_UserOfflineSmall Offline
2
January 4, 2018 - 9:37 am
sp_Permalink sp_Print

See REST API documentation for the appropriate syntax. 

Does this code work to update a single field?  I think you may need a "?" before the api key.

https://api.thingspeak.com/update?api_key=xxxxxxxxxxxxxxxx&field1=0

Then continue to append fields with the "&".

https://api.thingspeak.com/update?api_key=xxxxxxxxxxxxxxxx&field1=0&field2=56&field3=123

Can you describe your hardware?

Avatar
royalghost
New Member
Forum Posts: 1
sp_UserOfflineSmall Offline
3
January 9, 2018 - 3:57 am
sp_Permalink
Awaiting Moderation

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
27 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 252

Vinod: 164

cstapels: 96

piajola: 75

vespapierre: 63

Adarsh_Murthy: 59

Newest Members:

candacele1

WilliamBer

roxieob18

Metawatch

ozayagw

ubabeutiti

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

 

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Administrators: Hans, lee