Main Content

Results for

Good morning,
I am working on a smart garden project with an Arduino MKR WIFI 1010 and I am using Thingspeak as dashboard for monitoring some quantities (e.g. temperature, humidity, moisture, etc.). However, I would like to add a widget in order to change the state of my relay connected to the waterpump, for example if the variable "waterpump_state" is 0 turn off the pump, otherwise turning on. Do you think is it possible to implement it on Thingspeak? Among the predefined widget I have not found any useful in this sense.
Thanks in advance,
Lorenzo
Hello,
I am setting up a home energy monitoring system, all started from a blank sheet in arduino and its really working very well.
I would like to send data to thinkspeak which is not time dependant, i.e. send the X and Y values and format as a bar graph. The reason is, i have 12 channels monitoring energy (Wh) and i have this in an array which i plot on a local LCD and throughout the day the bars grow in height as the usage attributed to that channel grows. How can i do something similar in thing speak which by default applies a time stamp to received data.
Very simply, each channel has an ID (0-11) and a number associated with the accumulative Wh. I have a similar thing in excel for development where my serial port data is saved to a csv which excell imports every minute and updates a bar graph a bit like this;
Ive had a good look (perhaps not good enough!) and i just cant see how this may be acheived with thingspeak without a clumbersome combination of 2 channels (given each channel has 8 fields) and then using a matlab visualisation to pull it all together. Perhaps its not has hard / messy as it sounds? I am paid user so can create extra channels if required.
Thanks,
Stuart
Hi there,
I am attempting to obtain a location history (thus the location of each of the previous messages recived) and the current location of my device on Thingspeak. I have not found any examples of how to do this on Thingspeak. Please may someone guide me or advise me on how to do this.
Thank you
Hi there, I have been attempting to try and access the loaction of my device using the following code:
myChannel=*******;
ReadAPIKey='xxxxxxxxxxxx';
myData=thingSpeakRead(myChannel,'ReadKey', ReadAPIKey,'numpoints',100,'outputformat','timetable','location',1);
myVector=(myData.Latitude).^2+(myData.Longitude).^2+myData.Altitude.^2;
maxVector=max(myData.Latitude)^2+max(myData.Longitude)^2+max(myData.Altitude)^2;
myVector=myVector/maxVector;
myMap=geoscatter(myData.lat,myData.long,15,myVector,'filled');
geobasemap('satellite');
colormap jet;
I have about 100 entry points at this stage. However, i get the following error:
Error using .
Unrecognized table variable name 'lat'.
Error in Custom (no starter code) 2 (line 7)
myMap=geoscatter(myData.lat,myData.long,15,myVector,'filled');
I am attempting to access the location of a moving device. Meaning, the longitude and latitude values will be constantly changing, thus, I do not want to set my latitude or longitude value as a constant but i want it to keep on updating as my device moves around. How would I do this? How would I ammend this error without setting the "lat" or "long" as a consant before hand?
Further, my device should be constantly sending messages, this, the number of entries to which it will see the location of will be contantly changing. How can I thus not set the entry points as a specific value but rather have it update as my device sends messags?
Is there an easier or better way to do this?
Thanks
Hi there, I am trying to reach out to anyone who has successfully completed the project of building a weather station using an Arduino MKRFOX1200 board, a dht11 sensor across the Sigfox and Thingspeak networks. I’ve been attempting to build the weather station over the SigFox and things.io network for over a year now but I was unsuccessful. I then found this tutorial on how to build this using Thingspeak: https://create.arduino.cc/projecthub/masteruan/arduino-mkr-fox-1200-sigfox-meteo-station-423609 . I have now been attempting to build it using this network but am still unsuccessful.
My SigFox and arduino is working. I made the arduino code convert temperature to Celsius (rather than Kelvin which is what the tutorial does). However, I am unable to access the location of the device on Thingspeak (my SigFox atlas is activated) and I am getting humidity values of approximately -30k. Please may someone assist me or give me a detailed approach on how to fix these issues. My goal is to have my thingspeak like this: https://thingspeak.com/channels/227248. I have followed the tutorial and projecthub but I cannot figure out why I am obtaining a confusing humidity reading. Please please may someone help.
Thank you so much for your time.
I work with an Arduino device. I have subscribed separately two thingspeak devices that works properly. Every device has a channel and I would like to publish on both channel using an only device.
I have added the second channel to the first device(see image).
Althougt this device can publish on both channel separately, I can't publish at the same time (after a few seconds, obviously). When I try to publish both of then, no one works.
Hi, there ! Need some serious help.... I have trouble trying to upload my data to my Channel. Any ideas to fix it?
Below you can see my code:
#include <ThingSpeak.h>// Η βιβλιοθήκη του ThingSpeak.
#include <SPI.h>
#include <Ethernet.h>
#include <SoftwareSerial.h>
#include <Servo.h> // Η βιβλιοθήκη του σερβοκινητήρα.
#include "DHT.h"
#include "MQ7.h"
//Για τον αισθητήρα DHT11.
#define DHTPIN 7
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
//Για τον φωτισμό.
#define DELAY 5000 // Καθυστέρηση μεταξύ μετρήσεων σε ms για τον φωτισμό.
#define VIN 5 // Τάση 5V.
#define R 10000 //Αντίσταση 10.000 Ω.
//Για τον αισθητήρα MQ7.
int MQ7pin = A0;
int MQ7Reading;
int MQ7led = 3;
//Για τον αισθητήρα Soil.
int val;
int soil_dig= 8;
int soil_analog = A1;
//Μεταβλητές για τον φωτισμό και για τον υπολογισμό lux.
const int sensorPin = A3; // Το pin στο οποίο συνδέεται ο αισθητήρας.
const int led = 12;
const int greenled = 10;
const int redled = 4;
const long onduration = 10000;
const long offduration = 30000;
int ledstate = HIGH;
long remembertime = 0;
int sensorVal; // Αναλογική τιμή από τον αισθητήρα.
int lux; //Τιμές για τα lux
int valvePin = 13; // Το pin στο οποίο συνδέεται το ρελέ, ώστε να ενεργοποιεί την ηλεκτροβάνα.
//Για τον αισθητήρα Ultrasonic.
#define echoPin 5 // Το echoPin.
#define trigPin 6 // To trigPin.
long duration; // Η διάρκεια που κάνει το ηχητικό κύμα να ταξιδέψει.
int distance; // Ο υπολογισμός της ταχύτητας του ηχητικού κύματος.
//Για τον αισθητήρα Rain.
const int rain_D = 2;//Ψηφιακή τιμή αισθητήρα βροχής.
const int rain_A = A2;//Αναλογική τιμή αισθητήρα βροχής.
int rain_val;// Μεταβλητή για την αποθήκευση της τιμής του αισθητήρα βροχής.
int r;// Μεταβλητή για την αποθήκευση της τιμής του αισθητήρα βροχής.
Servo servo; // Το όνομα του σερβοκινητήρα.
int servoPin = 11; // Το pin στο οποίο συνδέεται ο σερβοκινητήρας.
#define pwm 9 // Το pin στο οποίο συνδέεται ο ανεμιστήρας.
//Σύνδεση
String readString;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //H mac address.
byte ip[] = {192,168,2,123};
EthernetClient client;
unsigned long myChannelNumber = 1*******; //Ο αριθμός του καναλιού.
const char * myWriteAPIKey = "****************"; //Το ΑΡΙ Κey του καναλιού.
const int updateInterval = 10000;
void setup() {
Serial.begin(9600);
ThingSpeak.begin(client);// Σύνδεση στο cloud του ThingSpeak.
dht.begin();
pinMode(MQ7led, OUTPUT);// Θέτει το led του MQ7 ως OUTPUT.
pinMode(trigPin, OUTPUT); // Θέτει το trigPin ως OUTPUT.
pinMode(echoPin, INPUT); // Θέτει το echoPin ως INPUT.
pinMode(rain_D, INPUT); // Θέτει το rain_D ως INPUT.
pinMode(rain_A, INPUT); // Θέτει το rain_A ως INPUT.
pinMode(servoPin, OUTPUT);// Θέτει το servoPin ως OUTPUT.
servo.attach(servoPin);// Σύνδεση σε pin της μεταβλητής του σερβοκινητήρα.
analogWrite(pwm, 255);// Γράφει μία αναλογική τιμή (PWM pin) σε ένα pin.
pinMode(soil_analog, INPUT); // Θέτει το soil_analog ως INPUT.
pinMode(soil_dig, INPUT);// Θέτει το soil_dig ως INPUT.
pinMode(valvePin, OUTPUT); //Θέτει το 13 ως OUTPUT pin, ώστε να στέλνει σήμα στο relay.
pinMode(led, OUTPUT); // Θέτει το ledPin ως output.
digitalWrite(led,ledstate);
pinMode(sensorPin, INPUT);// Θέτει το sensorPin ως INPUT.
pinMode(greenled, OUTPUT);// Θέτει το greenled ως OUTPUT.
pinMode(redled, OUTPUT);// Θέτει το redled ως OUTPUT.
}
void loop() {
Serial.println(F("======================================"));
Serial.println(F("Συνθήκες στο Θερμοκήπιο :"));
//DHT11
float t = dht.readTemperature();// Η θερμοκρασία σε °C.
float h = dht.readHumidity(); // Η υγρασία του χώρου.
float f = dht.readTemperature(true); //Η θερμοκρασία σε °F.
// Υπολογισμός του heat index, ο οποίος πρέπει να μετατραπεί σε Fahrenheit.
float hi = dht.computeHeatIndex(f, h);
Serial.print(F("Temperature: "));
Serial.print(t);
Serial.print(F("°C "));
Serial.print(F(" and "));
Serial.print(f);
Serial.print(F("°F\t"));
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F(" %\t"));
Serial.print(F("Heat index: "));
Serial.print(hi);
Serial.println(F(" °F"));
// Έλεγχος της θερμοκρασίας , ώστε να ενεργοποιείται ο ανεμιστήρας όποτε χρειάζεται.
if (t == 26)
{
analogWrite(pwm, 51);
Serial.print(F("Ταχύτητα ανεμιστήρα: 20% "));
delay(1000);
}
else if (t == 30)
{
analogWrite(pwm, 204);
Serial.print(F("Ταχύτητα ανεμιστήρα: 80% "));
delay(1000);
}
else if (t > 40 )
{
analogWrite(pwm, 255);
Serial.print(F("Ταχύτητα ανεμιστήρα: 100% "));
delay(1000);
Serial.print(F("\t"));
}
//MQ7
float g = analogRead(MQ7pin);
Serial.print(F("MQ7: "));
Serial.println(g);
// Έλεγχος της τιμής του MQ7, ώστε να ανάβει το led που αναπαριστά ανεμιστήρα.
if ( g < 200)
{
Serial.println(F("O ανεμιστήρας κλειστός - Φυσιολογική ποσότητα CO στον χώρο εργασίας."));
digitalWrite(MQ7led, LOW);
}
else if (201 < g && g < 220)
{
Serial.println(F("Η μέγιστη φυσιολογική ποσότητα CO για χώρους εργασίας ξεπεράστηκε!!!- Λειτουργία εξαερισμού στο 50%."));
digitalWrite(MQ7led,HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(MQ7led, LOW); // turn the LED off by making the voltage LOW
delay(1000);
}
if (g > 220)
{
Serial.println(F("Eπικίνδυνα αέρια CO !!!- Λειτουργία εξαερισμού στο 100%."));
digitalWrite(MQ7led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(5000);
}
//Soil Humidity
int soil_analog_value = analogRead(soil_analog);
soil_analog_value = map(soil_analog_value, 0, 1023, 230, 0);//Συνάρτηση map για μετρατροπή τιμής σε %.
val = digitalRead(soil_dig);
Serial.print(F("Soil moisture (Αναλογική τιμή) : "));
Serial.print(soil_analog_value);
Serial.print(F("\t"));
//Έλεγχος υγρασίας εδάφους για αυτόματο πότισμα.
if (soil_analog_value < 50)
{
digitalWrite(valvePin, LOW); //Όταν η τιμή γίνει LOW,τότε και το relay πρέπει να λάβει τιμή LOW.
Serial.println(F("relay on"));
}
else
{
digitalWrite(valvePin, HIGH); //Όταν η τιμή γίνει HIGH, τότε και το relay πρέπει να λάβει τιμή HIGH.
Serial.println(F("relay off"));
}
//Ultrasonic Sensor
// Αρχικοποίηση του trigPin.
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Το trigPin σε HIGH (ACTIVE) για 10 μs.
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
//Διαβάζει το echoPin, επιστρέφει το χρόνο του ηχητικού κύματος σε μs.
duration = pulseIn(echoPin, HIGH);
// Υπολογισμός απόστασης.
distance = (duration - 10) * 0.034 / 2;
Serial.println("");
Serial.print(F("Distance: "));
Serial.print(distance);
Serial.print(F(" cm"));
//Rain Sensor
rain_val = digitalRead(rain_D);
r = analogRead (rain_A);
r = abs ((100*r-40000)/623);
Serial.println(F(""));
Serial.print(F("Rain (Αναλογική τιμή) :"));
Serial.print(r);
Serial.print(F("\t"));
Serial.print(F("Rain (Ψηφιακή τιμή) :"));
Serial.print(rain_val);
//Έλεγχος για λειτουργία του σερβοκινητήρα.
if ((rain_val != HIGH) && (distance < 9)) {
servo.write(0);
}
if ((rain_val != HIGH) && (distance > 9)) {
servo.write(90);
}
else {
servo.write(0);
}
//Μέτρηση τιμής της φωτοαντίστασης και μετατροπή σε lux.
sensorVal = analogRead(sensorPin);
lux=sensorRawToPhys(sensorVal);
Serial.print("Raw value from sensor= ");
Serial.println(sensorVal); //Τύπωση αναλογικής τιμής.
Serial.print("Physical value from sensor = ");
Serial.print(lux); //Τύπωση αναλογικής τιμής.
Serial.println(" lumen");
//Συνθήκες για το άνοιγμα των led και των κουρτινών σκίασης σε διάφορες γωνίες.
if (ledstate == HIGH){
if((millis() - remembertime) >= onduration){
ledstate = LOW;
remembertime = millis();
}
}
if (ledstate == LOW){
if((millis() - remembertime) >= offduration){
ledstate = HIGH;
remembertime = millis();
}
}
//Lux.
if (lux < 100){
digitalWrite(led, HIGH);
if (lux < 200){
digitalWrite(greenled, ledstate);
if (lux < 300){
digitalWrite(redled, ledstate);
}}}
if(lux > 350){
digitalWrite(redled, LOW);
if(lux > 450){
digitalWrite(greenled, LOW);
if (lux>600){
digitalWrite(led, LOW);
}}}
else
digitalWrite(led,ledstate);
//Τα δεδομένα για το ThingSpeak, τα οποία στέλνονται στα αριθμημένα fields.
ThingSpeak.writeField(myChannelNumber,1,t, myWriteAPIKey);
ThingSpeak.writeField(myChannelNumber,2,h ,myWriteAPIKey);
ThingSpeak.writeField(myChannelNumber,3,g ,myWriteAPIKey);
ThingSpeak.writeField(myChannelNumber,4,soil_analog_value, myWriteAPIKey);
ThingSpeak.writeField(myChannelNumber,5,distance, myWriteAPIKey);
ThingSpeak.writeField(myChannelNumber,6,r, myWriteAPIKey);
delay(15000);
}
int sensorRawToPhys(int raw){
// Conversion rule
float Vout = float(raw) * (VIN / float(1023));// Conversion analog to voltage
float RLDR = (R * (VIN - Vout))/Vout; // Conversion voltage to resistance
int phys=500/(RLDR/1000); // Conversion resitance to lumen
return phys;
}
Good morning,
I'm working with an Arduino MKR 1010 which takes information about weather from the website "api.openweathermap.org". On a ThingSpeak dashboard I displayed the main numbers (float) information like: temperature, wind speed, humidity, etc. Moreover, from the openweathermap I can also get string sentence (e.g. "light rain" or "broken clouds" etc.). I'm wondering if there is a way to display on the ThingSpeak dashboard string fields. Indeed, in the ThingSpeak Channel Settings I added an extra Field in order to store these string words but I don't know how to print them in the dashboard.
Someone can help me?
Thanks in advance,
Lorenzo

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 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