Is there any reason an Arduino Primo cannot send data to my ThingSpeak field?

2 views (last 30 days)
Does the device need to have a secure protocol? The Primo does not.
  7 Comments
Dale Lamb
Dale Lamb on 17 Mar 2020
Edited: Dale Lamb on 17 Mar 2020
I included the avr/dtostrf.h to my script, compiler accepted it, but I still get the same error message on the dtostrf line in the ThingSpeak file. I also tried adding delays in the "Wireless Network Signal Strength" code (as suggested above) at several points but still get no update. Where does the delay go and how much delay is enough? Could the Primo's 32 bit "int" be causing problems?
Christopher Stapels
Christopher Stapels on 17 Mar 2020
in the http request function, add some delay after the post is sent. 200 ms should do, but I suggest you start with 500 and work down.
// POST data to ThingSpeak.
if (client.connect(server, 80)) {
client.println("POST /update HTTP/1.1");
client.println("Host: api.thingspeak.com");
client.println("Connection: close");
client.println("User-Agent: Primo");
client.println("X-THINGSPEAKAPIKEY: "+writeAPIKey);
client.println("Content-Type: application/x-www-form-urlencoded");
client.print("Content-Length: ");
client.print(data.length());
client.print("\n\n");
client.print(data);
% ADD DELAY HERE
delay(500);
Serial.println("RSSI = " + String(field1Data));
lastConnectionTime = millis();
}
}
client.stop();

Sign in to comment.

Accepted Answer

Dale Lamb
Dale Lamb on 18 Mar 2020
Edited: Dale Lamb on 19 Mar 2020
It Worked!!!! I got it to work with a delay as low as 40 msec, but set it to 80 msec for margin.
Thank you Christopher Stapels for seeing me through this!
Recap: Send data to ThingSpeak using Arduino Primo
Two approaches were reccommended, approach 2 worked
1). The approach shown in https://github.com/mathworks/thingspeak-arduino did not work for my Primo, the error suggesting a problem with dtostrf, even when the library was added. Was unable to resolve due to my limited experience/time availability.
2). I modified Arduino IDE's Example/WifiLink/WifiWebClient.ino by swapping in the POST commands found in the ThingSpeak example "Wireless Network Signal Strength" with a delay added as per Christopher Stapels previous comment. Success was achieved. :)
  1 Comment
Christopher Stapels
Christopher Stapels on 18 Mar 2020
The bad example was my fault, so the least I can do is to see you through it. Thanks for letting me know it worked! I would still reccomend a bit more than 80 just to be safe. Unless you are really power strapped, 200 ms shouldnt hurt. The best thing to do is to actually poll for a response from the server, then you dont have to wait an arbitrary time. The ThingSpeak library does this, but I am sorry it wont compile for you. I read that you can also add a version of the dtostr function in the code yourself if you wish. Anyway, happy thingpseaking!

Sign in to comment.

More Answers (0)

Communities

More Answers in the  ThingSpeak Community

Categories

Find more on Read Data from Channel in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!