Quantcast
Channel: ThingSpeak IoT Community - Forum: Arduino
Viewing all articles
Browse latest Browse all 172

heinb on Need help posting data using RN171 wifi shield and wifly library

$
0
0

I managed to solve the issue.  Here are the steps that might help, even for those who uses other hardware and libraries:

1. I knew that the url to post worked when I put it in a web browser - it updated my feed:

https://api.thingspeak.com/update?key=xxxxxxxxxxxxxx&field1=10    (obviously I replaced the x's with my write key)

2. I was thinking that my shield was adding info to my header and this caused  the "Bad Request" error, so I went to 

http://web-sniffer.net/

and posted my url into the box provided.  This then returned the info sent to the server and it looked like this:

Connect to 52.7.53.111 on port 443 ... ok

GET /update?key=PONK48XZ3V2APBKW&field1=10 HTTP/1.1[CRLF]
Host: api.thingspeak.com[CRLF]
Connection: close[CRLF]
User-Agent: Web-sniffer/1.1.0 (+http://web-sniffer.net/)[CRLF]
Accept-Encoding: gzip[CRLF]
Accept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7[CRLF]
Cache-Control: no-cache[CRLF]
Accept-Language: de,en;q=0.7,en-us;q=0.3[CRLF]
Referer: http://web-sniffer.net/[CRLF]
[CRLF]


From there I created my commands to the website by changing the code in my function.  This is the working function:

Command to call the function in my main loop:

ThingSpeakUpdate("field1="+String(x)+"&field2="+String(y));
delay(15000);


And here is my working function:

void ThingSpeakUpdate(String tsData)
{
 Serial.println("Data string: " + tsData);

 Serial.println("...Connecting to Thingspeak");

 // Connecting and sending data to Thingspeak
 
 if(Wifly.connect("api.thingspeak.com","80"))
 {
 Serial.println("...Connection succesful, updating datastreams");
 
 Wifly.println("GET /update?key=PONK48XZ3V2APBKW&"+tsData+" HTTP/1.1");
 Wifly.println("Host: api.thingspeak.com");
 Wifly.println("Connection: close");
 delay(200);
 Serial.println("Thingspeak update sent.");
 }
 else{
 // Failed to connect to Thingspeak
 Serial.println("Unable to connect to Thingspeak.");
 }

Interestingly enough, I did not have to specify the packet lenght.  I hope this helps others aswell.

Viewing all articles
Browse latest Browse all 172

Trending Articles