Main Content

Results for

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.

MATLAB Documentation
47%
Videos
14%
MOOCs
2%
MATLAB Central Community
14%
Examples
22%
Other(Explain in comments)
2%
2608 votes

R2021b is live! There are two new products, five major updates, and hundreds of other feature updates in this latest release. Download or access MATLAB Online to discover what’s new.

New Products

Major Updates

  • Lidar Toolbox - Use Lidar Viewer app to visualize, analyze, and preprocess lidar point clouds interactively
  • Simulink Code Inspector - Use Code Inspector contextual tab to check compatibility, inspect code and view results directly in the model
  • Simulink Control Design - Design Model Reference Adaptive Controllers
  • Symbolic Math Toolbox - Get guidance for symbolic workflows with next-step suggestions in MATLAB Live Editor
  • Wavelet Toolbox - Use wavelet analysis to process and extract features for signals and images for AI workflows

Check out our release highlight page for details.

Share your experience with the community

Are there any new features you find particularly useful? Are you trying the new product to solve a particular problem? Share your story with us no matter it’s big or small. We plan to publish those stories in the highlight channel so that community users can get more out of the new release. A good example is an article written by Adam Danz . If you are interested, contact me via email on my profile card.

what happen to thingspeak? it also loading so slow. it happen for almost a week, until now it has not been like normal

I am using a Microsoft surface laptop (running on Microsoft RT) and using a Explorer browser (which unfortunately cannot be upgraded to Microsoft Edge, or replaced by Chrome or Firefox). Until end of August 2021 I could log into ThingSpeak, with the login (email) entry fields in page https/:thingspeak.com (after clicking "Get started for free"). However since end of August this email entry item does not appear anymore on the webpage of thingspeak.com on my Surface. So I can't login anymore and thus can't use Thingspeak anymore on my Surface RT laptop. This is rather frustrating. Is there a possibility of provide arguments to the URL so that I can login directly (e.g. https://thingspeak.com/login?email?password, or something similar) or do you know another way to login. Your help is greatly appreciated.

My goal is to get the data from two DHT22 sensors, with a single sensor I had no problem but with two sensors I get only a few data and then it interrupts reporting "Read DHT22 failed." I share my code, any suggestions I appreciate

    #include <SimpleDHT.h>
    #include <ESP8266WiFi.h>
    String apiKey = "xxxxx";
    const char* ssid = "xxxxx";
    const char* password = "xxxxx";
    const char* server = "api.thingspeak.com";
    int pinDHT22 = D0;
    int pinDHT221 = D1;
    SimpleDHT22 dht22(pinDHT22);
    SimpleDHT22 dht221(pinDHT221);
    WiFiClient client;
    void setup() {
      Serial.begin(115200);
      delay(10);
      WiFi.begin(ssid, password);
      Serial.println();
      Serial.println();
      Serial.print("Connecting to ");
      Serial.println(ssid);
      WiFi.begin(ssid, password);
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }
      Serial.println("");
      Serial.println("WiFi connected");
    }
    void loop() {
     byte temperatura = 0;
     byte humedad = 0;
     byte temperatura1 = 0;
     byte humedad1 = 0;
      if (dht22.read(pinDHT22, &temperatura, &humedad, NULL)) {
        Serial.print("Read DHT22 failed.");
        return;
      }
      if (dht221.read(pinDHT221, &temperatura1, &humedad1, NULL)) {
        Serial.print("Read DHT221 failed.");
        return;
      }
      if (client.connect(server,80)) {
        String postStr = apiKey;
        postStr +="&field1=";
        postStr += String((int)temperatura);
        postStr +="&field2=";
        postStr += String((int)humedad);
        postStr +="&field3=";
        postStr += String((int)temperatura1);
        postStr +="&field4=";
        postStr += String((int)humedad1);
        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.println("% send to Thingspeak");
      }
      client.stop();
      Serial.println("Waiting…");
      delay(120000);
    }

Hi,

I have this code posting data. It used to work a couple of years back but now it shows no new data being posted and I want to see what the error is:

#include <Bridge.h>
#include <BridgeServer.h>
#include <BridgeClient.h>
#include <DHT.h>
#define DHTPIN 4 
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
//********************
#define ARRAY_SIZE 2
String API = "13xxxxxxxxxxxxx";
unsigned long previousMillis = 0;        // will store last time LED was updated
const long interval = 900000;           // interval at which to blink (milliseconds)
void setup() {
  Bridge.begin();
  Console.begin();
  dht.begin();
  Serial.begin(9600);
  Serial.println("set up");
}
//********************
void postToThingSpeak(String key, float value[]) {
  Process p;
  String cmd = "curl -d \'key="+key;
  for (int i=0;i<ARRAY_SIZE;i++) {
    cmd = cmd + "&field"+ (i+1) + "=" + value[i];
  }
  cmd = cmd + "\' http://api.thingspeak.com/update";
  p.runShellCommand(cmd);
  Console.println(cmd);
  p.close();
  Serial.println("posted");
}
void loop() {
    unsigned long currentMillis = millis();
    if (currentMillis - previousMillis >= interval) {
      // save the last time you blinked the LED
      previousMillis = currentMillis;
      float temperature = dht.readTemperature();
      //float temperature = 33.33;
      Console.println(temperature);
      float humidity = dht.readHumidity();
      //float humidity = 44.44;
      Console.println(humidity);
      float vol[ARRAY_SIZE];
      vol[1] = temperature;
      vol[0] = humidity;
      postToThingSpeak(API, vol); //ACCOUNT
    }
    //delay(120000); // ThingSpeak will only accept updates every 15 seconds.
  }

Hi, I've been using ThingSpeak now for a number of years capturing temperature data from a Pi zero and Python. I currently use the Unsecured TCP option, but the recent email about moving to mqtt3 server suggests websockets. I've looked at the example and understand username, password and channel ID, but not what the Client ID is. Can someone tell me what this is please.

Many thanks Alastair

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

Join our celebration of the 20th anniversary of MATLAB Central community! You are invited to enter 2 contests - A Treasure Hunt and a MATLAB Mini Hack - to have fun and win prizes.

How to Play

  • In the Treasure Hunt, complete 10 fun tasks to explore the ‘treasures’ in the community.
  • In the MATLAB Mini Hack, use up to 280 characters of MATLAB code to generate an interesting image. Simply vote for the entries that you like or share your own entries to gain votes.

Prizes

You will have opportunities to win compelling prizes, including special edition T-shirts, customized T-shirts, Amazon gift cards, and virtual badges. Your participation will also bump up our charity donations.

Ready to participate?

Visit the community contests space and choose the contest you’d like to enter. Note that:

  • You need a MathWorks account to participate. If you don’t have a MathWorks account, you can create one at MathWorks sign in .
  • Make sure you follow the contests (click the ‘follow the contests’ button on the top) to get notified for prize information and important announcements.

For the full contest rules, prizes, and terms, see details here .

We hope you enjoy the contests and win big prizes. NOW, LET THE CELEBRATION BEGIN!

Hi, I am using SIM800 for transferring data to the ThingSpeak server. After send OK, I am not getting acknowledgment from ThingSpeak. Also, the field is not getting updated in ThingSpeak. Let me know what has gone wrong. The commands and response in teraterm is as below.

AT+CIPSHUT

SHUT OK

AT

OK

AT+CIPMUX=0

OK

AT+CGATT=1

OK

AT+CSTT="airtelgprs.com","",""

OK

AT+CIICR

OK

AT+CIFSR

100.67.75.225

AT+CIPSTART="TCP","184.106.153.149","80"

OK

CONNECT OK

AT+CIPSEND

> GET /update?api_key=81XXXXXXXXXXXXX4&field1=32

SEND OK

CLOSED

I'd appreciate comment on whether I understand the limitations with MQTT and low power. Using deep sleep the ESP12 consumes microamps and my sensor is insignificant. The big drain on the battery is WiFi. Sending an MQTT message is taking around 10ms which seems at first sight promising. Unfortunately it looks to me like deep sleep ends the connection, and reconnection takes 4 or more seconds. I'd thought that deep sleep, static IP, and MQTT were the way to get very low power consumption but it looks to me like they don't solve the problem.

Water
27%
Tea
13%
Coffee
28%
Juice
4%
Something harder
18%
Nothing, I'm good
10%
13353 votes

Hi , I am using M66 GSM Module to send and recv data over Thingspeak , TCP Connection : "api.thingspeak.com"; : Working Fine "GET /update?api_key=xxxxxxxxxxxxxxxx&field1=14"; : Send data to Server No Issue "GET https://api.thingspeak.com/update?api_key=xxxxxxxxxxxxxxxx&field1=12"; : Send sata to server No Issue .

But not able to see data in thingspeak view , it means thingspeak server not collecting data from M66 Module .

Could you please help the same .

Please can I run my MATLAB code on the cloud? The code involves calling the fuzzy logic toolbox for irrigation control and also collecting sensor data from farm.

Using the gauge widget works good, and the current value shows up below the gauge. But I've seen articles where the value is shown inside the gauge, not below it. It that possible to do? If so, how?

I do really like the ability of applying colors to ranges of the gauge's values. I'm plotting Air Quality AQI numbers and this works really well for that.

Thanks,

Rick

I am a new user to ThingSpeak. Generally things are going well. I've been able to create channels and use widgets. I am embedding charts into my own web site (using Google Sites) and that is working fine.

My question has to do with labels that I put on the charts in the 'public view'. I can change the title and the X and Y axis text and this shows up as I want. But when I click on the 'export URL' button and a new tab opens up with the chart, the title and X & Y labels are not what I put in (and yes, I did 'save' after changing them). Is this a bug, or is there some other thing I need to do here?

Thanks,

Rick

Im posting data every 10 minutes to this field as you can see, yet when i pull the data back down there are 2 timestamps in between each post with 'nothing' in them which in tern screws up any matlab script trying to average the data. Why is this happening? thanks see below

created_at,entry_id,field2
2021-08-21 09:54:27 -0600,38811,5.416666666666667
2021-08-21 09:57:02 -0600,38812,
2021-08-21 10:03:59 -0600,38813,
2021-08-21 10:04:27 -0600,38814,5.0
2021-08-21 10:07:02 -0600,38815,
2021-08-21 10:13:59 -0600,38816,
2021-08-21 10:14:28 -0600,38817,5.0
2021-08-21 10:17:03 -0600,38818,
2021-08-21 10:23:59 -0600,38819,
2021-08-21 10:24:28 -0600,38820,5.416666666666667
2021-08-21 10:27:03 -0600,38821,
2021-08-21 10:34:00 -0600,38822,
2021-08-21 10:34:29 -0600,38823,8.333333333333334
2021-08-21 10:37:04 -0600,38824,
2021-08-21 10:44:00 -0600,38825,
2021-08-21 10:44:29 -0600,38826,6.25
2021-08-21 10:47:09 -0600,38827,
2021-08-21 10:54:01 -0600,38828,
2021-08-21 10:54:30 -0600,38829,6.666666666666667
2021-08-21 10:57:10 -0600,38830,
2021-08-21 11:04:01 -0600,38831,
2021-08-21 11:04:34 -0600,38832,7.083333333333334
2021-08-21 11:07:10 -0600,38833,
2021-08-21 11:14:01 -0600,38834,
2021-08-21 11:14:35 -0600,38835,9.583333333333334
2021-08-21 11:17:11 -0600,38836,
2021-08-21 11:24:02 -0600,38837,
2021-08-21 11:24:35 -0600,38838,7.083333333333334