Results for


I am working with an Arduino nodemcu board and a Tmp36 sensor. My channel updates fine if I use my browser with the following: https://api.thingspeak.com/update?api_key=xxxxxxxxx&field1=71, but does not update with the following sketch, although the serial monitor shows the commands are executed:
//Source code to the Temperature Sensor and ThingSPeak Server Blog String ssid = "XXX"; // SSID to connect to String password = "XXX"; // Our virtual wifi has no password (so dont do your banking stuff on this network) String host = "api.thingspeak.com"; // Open Weather Map API const int httpPort = 443; String uri = "/update?api_key=XXXX&field1=";
int setupESP8266(void) { // Start our ESP8266 Serial Communication Serial.begin(115200); // Serial connection over USB to computer Serial.println("AT"); // Serial connection on Tx / Rx port to ESP8266 delay(10); // Wait a little for the ESP to respond if (!Serial.find("OK")) return 1;
// Connect to 123D Circuits Simulator Wifi Serial.println("AT+CWJAP=\"" + ssid + "\",\"" + password + "\""); delay(10); // Wait a little for the ESP to respond if (!Serial.find("OK")) return 2;
// Open TCP connection to the host: Serial.println("AT+CIPSTART=\"TCP\",\"" + host + "\"," + httpPort); delay(50); // Wait a little for the ESP to respond if (!Serial.find("OK")) return 3;
return 0; }
void anydata(void) {
int temp = map(analogRead(A0),20,358,-40,125);
// Construct our HTTP call String httpPacket = "GET " + uri + String(temp) + " HTTP/1.1\r\nHost: " + host + "\r\n\r\n"; int length = httpPacket.length();
// Send our message length Serial.print("AT+CIPSEND="); Serial.println(length); delay(10); // Wait a little for the ESP to respond if (!Serial.find(">")) return -1;
// Send our http request Serial.print(httpPacket); delay(1000); // Wait a little for the ESP to respond if (!Serial.find("SEND OK\r\n")) return;
}
void setup() {
setupESP8266();
}
void loop() {
anydata();
delay(10000); }
Hi,
I am using Ublox SARA-R410M to send (cellular) data to ThingSpeak cloud. I found in the Ublox manual that AT+UHTTPC (POST data command) can do the job. The link below is the location which my data will be saved on ThingSpeak (field1):
"https://api.thingspeak.com/update?api_key=WRITE_API_KEY&field1="
Note that the "WRITE_API_KEY" is 16 characters (combination of letters and numbers).
AT command: AT+UHTTPC=<profile_id>,5, path,<filename>,<data>,<HTTP_content_type>
Based on the information above, which items should I use for path and filename? And how can I use this command in Arduino code?
I appreciate any help in advance.
Abbas
I am using TX and RX pin of arduino connect to RX and TX pin of NodeMCU. The data does not received, the data upload to thingspeak is zero.
I was testing some sensors using code that I've run before successfully on an Arduino device to update to thingspeak, but I keep getting the http error code -302.
if true % code #include <SPI.h> #include <WiFi101.h> #include <Wire.h> #include <secrets_new.h> #include <ThingSpeak.h> #include <SD.h>
char ssid[] = SECRET_SSID; // your network SSID (name)
WiFiClient client;
unsigned long myChannelNumber = SECRET_CH_ID; const char * myWriteAPIKey = SECRET_WRITE_APIKEY;
int soil_moisture_2cm = 0; int soil_moisture_5cm = 0; int soil_temperature_2cm = 0; int soil_temperature_5cm = 0;
void setup() { // put your setup code here, to run once: WiFi.setPins(8,7,4,2); Wire.begin(); delay(1000); Serial.begin(9600);
if (WiFi.status() == WL_NO_SHIELD) { Serial.println("Communication with WiFi module failed!"); // don't continue while (true); }
String fv = WiFi.firmwareVersion(); if (fv != "1.0.0") { Serial.println("Please upgrade the firmware"); }
ThingSpeak.begin(client);
}
void loop() {
if(WiFi.status() != WL_CONNECTED){ Serial.print("Attempting to connect to SSID: "); Serial.println(SECRET_SSID); while(WiFi.status() != WL_CONNECTED){ WiFi.begin(ssid); // Connect to WPA/WPA2 network. Change this line if using open or WEP network Serial.print("."); delay(5000); } Serial.println("\nConnected.");
}
soil_moisture_2cm = analogRead(A0); soil_moisture_5cm = analogRead(A1); soil_temperature_2cm = analogRead(A2); soil_temperature_5cm = analogRead(A3);
ThingSpeak.setField(1, soil_moisture_2cm); ThingSpeak.setField(2, soil_moisture_5cm);
ThingSpeak.setField(3, soil_temperature_2cm); ThingSpeak.setField(4, soil_temperature_5cm);
int y = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); if(y == 200){ Serial.println("Channel 2 update successful."); }
else{ Serial.println("Problem updating channel 2. HTTP error code " + String(y)); } delay(30000); } end
How do I code my arduino sketch in order to get the HTTP response from an arduino post?
I am trying to migrate a project that used to post from an Arduino with a Tinysine Wifly shield (from Roving networks) to a php form/mysql db using this code snippet:
void reportToCloud() { data = ""; Serial.println("Reporting to cloud..."); if (wifly.available() > 0) { char ch = wifly.read(); Serial.write(ch); if (ch == '\n') { /* add a carriage return */ Serial.write('\r'); } }
if (wifly.open(site, 80)) { Serial.print("Connected to "); Serial.println(site);
// Set data to send static char outstr1[15]; static char outstr2[15]; static char outstr3[15]; static char outstr4[15];
String dataString1 = dtostrf(uvindex, 8, 2, outstr1); String dataString2 = dtostrf(mq2ratio, 8, 2, outstr2); String dataString3 = dtostrf(CO2PPM, 8, 2, outstr3); String dataString4 = dtostrf(temperature, 8, 2, outstr4); data = String("uvindex=" + dataString1 + "&mq2=" + dataString2 + "&age=" + dataString3 + "&name=" + dataString4); Serial.print(data); //name = temp && age = co2 //Reset all values uvindex = 0; mq2ratio = 0; CO2PPM = 0; temperature = 0;
/* Send the request */ wifly.println("POST /arduino/data_post.php HTTP/1.0"); wifly.println("Host: www.santiapps.com"); // SERVER ADDRESS HERE TOO wifly.println("Content-Type: application/x-www-form-urlencoded" ); wifly.print("Content-Length: "); wifly.println(data.length()); wifly.println(); wifly.print(data); Serial.println("Posted successfully"); } else { Serial.println(">>Failed to connect"); }
if (Serial.available() > 0) { wifly.write(Serial.read()); }
//Added Sat 14 Nov @820am wifly.close(); }
Now Im trying to make it post to thingspeak for improved analysis capabilities and what not. I get a post successful but I get no data in my thingspeak channel. I've checked the string used and its fine:
void reportToCloud() { data = ""; Serial.println("Reporting to cloud..."); if (wifly.available() > 0) { char ch = wifly.read(); Serial.write(ch); if (ch == '\n') { /* add a carriage return */ Serial.write('\r'); } }
if (wifly.open(site, 80)) { Serial.print("Connected to "); Serial.println(site);
// Set data to send static char outstr3[15]; static char outstr4[15]; String dataString3 = "33.33";//dtostrf(33.33, 8, 2, outstr3);//dtostrf(CO2PPM, 8, 2, outstr3); String dataString4 = "44.44";//dtostrf(44.44, 8, 2, outstr4);//dtostrf(temperature, 8, 2, outstr4); data = String("field3=" + dataString3 + "&field4=" + dataString4); //Serial.print(data); //for debugging
//Reset all individual values CO2PPM = 0; temperature = 0;
/* Send the request */ String postData = "POST /update?api_key=mykey&"+data+" HTTP/1.0"; //Serial.println(postData); wifly.println("Host: api.thingspeak.com"); // SERVER ADDRESS HERE TOO wifly.println("Content-Type: application/x-www-form-urlencoded" ); wifly.print("Content-Length: "); wifly.println(postData.length()); wifly.println(); wifly.print(postData); Serial.println("Posted successfully"); } else { Serial.println(">>Failed to connect"); }
if (Serial.available() > 0) { wifly.write(Serial.read()); }
//Added Sat 14 Nov @820am wifly.close(); }
postData is printed with this result:
printing co2... 87 105 102 108 121 45 87 101 98 false returned Free memory: 670 setPrompt hasnt been called Already joined network DeviceID: Wifly-WebClient2 Reporting to cloud... open santiapps.com 80 Connected to santiapps.com POST /update?api_key=mykey&field3=33.33&field4=44.44 HTTP/1.0 Posted successfully close: failed, no *CLOS* Reporting to cloud...
open santiapps.com 80 Connected to santiapps.com POST /update?api_key=mykey=33.33&field4=44.44 HTTP/1.0 Posted successfully close: failed, no *CLOS*
So basically the first snippet works fine and posts to the db via my php form and i can then read it off the db. The second snippet returns what seems to be a successful post but the data is not posted to thingspeak.
Afternoon Everyone, Looking for some help with my Arduino/Thingspeak sketch.
To give you an idea I have a Lora Sensor sending data to a Lora/Uno receiver, the data I receive is two strings, one for DO and one for Temp, in the parsepacket section below I convert the string to floats and use these as my fields for Thingspeak.
Currently the code allows a connection to Thingspeak, it also correctly associates the DO and Temp float variables with corresponding graphs on the channel.
However after the initial WiFi connection all that happens is zero is written to both graphs and only once, another write will not happen untill I reboot the Arduino.
I'm pretty certain that the order of my Loop is wrong.
My expected results are to write Temp and DO to Thingspeak every 30 seconds, with actual values, not 0. Currently a write happens once and Temp and DO are Zero, despite the packets being received correctly with actual values.
If I can clarify anything or better explain then please feel free to ask, I'm fairly new to this.
TIA. AC
if true #include <ESP8266WiFi.h> #include <ThingSpeak.h> #include <LoRa.h> #include <SoftwareSerial.h> #define nss D10 #define rst D14 #define dio0 D2 // WiFiClient client; // const char* ssid = "myssid"; const char* password = "mypassword"; // char thingSpeakAddress[] = "api.thingspeak.com"; unsigned long channelID = mychannelid; char* readAPIKey = "myapi"; char* writeAPIKey = "myapi"; unsigned long lastTime = 0; unsigned long timerDelay = 30000; unsigned int dataFieldOne = 1; unsigned int dataFieldTwo = 2; // float DO; float temp; // void setup() { WiFi.mode(WIFI_STA); ThingSpeak.begin(client); LoRa.setPins(nss, rst, dio0); Serial.begin(115200); while (!Serial); if (!LoRa.begin(868E6)) {//914E6 Serial.println("Starting LoRa failed!"); while (1); } } // void loop() { int packetSize = LoRa.parsePacket(); if (WiFi.status() != WL_CONNECTED) { Serial.print("Attempting to connect"); while (WiFi.status() != WL_CONNECTED) { WiFi.begin(ssid, password); delay(5000); if (packetSize) { Serial.print("packetSize = "); Serial.println(packetSize); parseLoRaPacket(); } ThingSpeak.setField(1, DO); ThingSpeak.setField(2, temp); int x = ThingSpeak.writeFields(channelID, writeAPIKey); // if (x == 200) { Serial.println("channel update succesful."); } else { Serial.println("Problem updating channel."); } } } } // void parseLoRaPacket() { String lora_data; // String as local variable // while (LoRa.available()) { lora_data = LoRa.readString(); Serial.print(lora_data); // int strIndex = lora_data.indexOf("TEMP: "); if (strIndex > -1) { int startPos = strIndex + strlen("TEMP: "); temp = lora_data.substring(startPos).toFloat(); Serial.println(temp); } strIndex = lora_data.indexOf("DO: "); if (strIndex > -1) { int startPos = strIndex + strlen("DO: "); DO = lora_data.substring(startPos).toFloat(); Serial.println(DO); } } } end
Kindly assist I have been trying to create a small weather station with with DHT11 sensor and CC3200 launchpad and connect it to ThingSpeak but the code won't compile as I am using an Arduino code.
Anyone to please help
if true #include <SPI.h> #include <WiFi.h> #include <WiFiClient.h> #include <DHT.h> // Including library for dht
String apiKey = ""; // Enter your Write API key from ThingSpeak
const char *ssid = "Virus"; // replace with your wifi ssid and wpa2 key const char *pass = ""; const char* server = "api.thingspeak.com";
#define DHTPIN 11 //pin where the dht11 is connected
#define DHT dht(DHTPIN, DHT11);
WiFiClient client;
void setup() { Serial.begin(115200); delay(10); dht.begin();
Serial.println("Connecting to "); Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected");
} void loop() {
float h = dht.readHumidity(); float t = dht.readTemperature();
if (isnan(h) || isnan(t)) { Serial.println("Failed to read from DHT sensor!"); return; }
if (client.connect(server,80)) // "184.106.153.149" or api.thingspeak.com {
String postStr = apiKey; postStr +="&field1="; postStr += String(t); postStr +="&field2="; postStr += String(h); postStr += "\r\n\r\n";
client.print("POST /update HTTP/1.1\n"); client.print("Host: api.thingspeak.com\n"); client.print("Connection: close\n"); client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n"); client.print("Content-Type: application/x-www-form-urlencoded\n"); client.print("Content-Length: "); client.print(postStr.length()); client.print("\n\n"); client.print(postStr);
Serial.print("Temperature: "); Serial.print(t); Serial.print(" degrees Celcius, Humidity: "); Serial.print(h); Serial.println("%. Send to Thingspeak."); } client.stop();
Serial.println("Waiting...");
// thingspeak needs minimum 15 sec delay between updates delay(1000); } end
The ThingSpeak Communication Library for Arduino, ESP8266 and ESP32 enables an Arduino or other compatible hardware to write or read data to or from ThingSpeak, an open data platform for the Internet of Things with MATLAB analytics and visualization.
Link: https://github.com/mathworks/thingspeak-arduino
Installation: In the Arduino IDE, choose Sketch/Include Library/Manage Libraries. Click the ThingSpeak Library from the list, and click the Install button.
Compatible Hardware:
- Arduino/Genuino or compatible using a WiFi Shield
- Arduino/Genuino or compatible using a WiFi Shield 101 (Use the WiFi101 library version 0.13.0 or older.)
- Arduino/Genuino or compatible using an Ethernet Shield
- Arduino/Genuino or compatible using a MKR ETH Shield
- Arduino MKR1000
- Arduino MKR1010
- Arduino VIDOR 4000
- Arduino GSM 14000
- Arduino Uno WiFi Rev2
- Arduino Yún (Rev1 and Rev2)
- ESP8266 programming directly (tested with SparkFun ESP8266 Thing - Dev Board and NodeMCU 1.0 module)
- ESP8266 via AT commands
- ESP32 (tested with SparkFun ESP32 Thing)
Tutorial: https://nothans.com/thingspeak-tutorials/arduino/send-data-to-thingspeak-with-arduino
I'm accessing internet on my Arduino uno using esp-01, is there a thingspeak Library i can use on this to send data to my thingspeak channel.
Hi - I'm currently using the code from this article: https://uk.mathworks.com/help/thingspeak/continuously-collect-data-and-bulk-update-a-thingspeak-channel-using-an-arduino-mkr1000-board-or-an-esp8266-board.html
My plan was to use this so as to update my Thingspeak server every second with data recorded on my arduino of higher than 1Hz. I am currently taking vibration sensor data that for my project requires a higher sample rate than Thingspeak is able to handle naturally - thus I found bulk updates to be the solution.
I have gotten this to work as specified in the article - updates every 2 minutes with data points at every 15 seconds. I have gotten this as far as data points every second with an update to the server every 10 second - however the system fails at any data point shorter than a second. I believe this to be a problem with using delta_t but I am not sure.
To clarify I do not have a computer science background, this is currently a project I'm working on in Mechanical engineering and I've truly hit a wall with this problem. Any help would be appreciated!
My system is an Arduino MEGA 2560 with an ethernet shield - in the sample code they use RSSI to output sample data, I simply changed this to a random number between 0-50.
https://developer.twitter.com/en/docs/twitter-api/tweets/lookup/introduction
Hello,
I try to do an aplication that warns me when is flood or when is a fire. I tryed to use ThingTweet to receive new status (better to send a message) when fire or flood happen. But not work that fine. Sometimes I receive a new status in my Tweeter account sometimes not. And this is the most annoying thing. To know that is working just some how. Digging for answers I didn't found much. But I saw Twitter changed the API version to: https://developer.twitter.com/en/docs/twitter-api/early-access. Please, I need some assistance to finish my project ! Thank you