University of the Incarnate Word in MATLAB Answers
上次活动时间: 2023-2-7

I have two seperate temperature sensors connected to arduino and I would like for them to read data on the same field in Thingspeak. For example, have one graph showing two lines on it in different colors, each representing one of the temperature sensor data. Is this possible? If so, how can it be done? Thank you
Lorenzo Scavarda in Discussions
上次活动时间: 2022-6-8

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 Display message on ThingSpeak Are you trying to display the text on your ThingSpeak channel? If so, you can use a MATLAB visualization, and use the text or annotate functions to put the text on a figure. Then add the visualization to your channel. When I've done this, i occasionally have to experiment with scaling the figure and text, but with a little work, you can definitely get what you want. Maybe you can use the Status field of the channel to display the text? Thanks Christopher for the answer. Yes, I though it but I have a doubt: what is the right function to retrieve the string (that I want to display) and put it in the annotate function? Because my problem is that the String is one of the Fields of my Channel. For example I found: data = thingSpeakRead(readChannelID,'Fields',field_number,NumPoints=3) but I don't how to handle a string variable. Is it enough use: data = thingSpeakRead(readChannelID,'Fields',field_number) Do you have some hints? Thanks a lot in advance, Cheers, Lorenzo Hi Vinod, yes, I'm using the Status Field indeed. However, it is not the best way because the layout and format of the text is very fixed, for example I can't use the "new line" but the text is in just one line. If I want to display a sort of weather report for the next hours of the day (i.e. not just one word but several sentences) is not very suitable. Either option you show above will work fine. dashboard string arduino api field
Hamidi Ismail in Discussions
上次活动时间: 2021-6-14

Currently i am able to send the 2 decimal data to thingspeak field. But i stuck on how to write 3 decimal places data to that field. Hope u guys can help.Here is my coding. #include <PubSubClient.h> // library used to publish the data through mqtt broker #include <WiFiEsp.h> // library for ESP8266 wifi #include <EEPROM.h> // library that GravityTds use #include <GravityTDS.h> // library that GravityTds use #include <OneWire.h> // Include the libraries for temperature #include <DallasTemperature.h> // Include the libraries for temperature #include <SoftwareSerial.h> // library for software serial to display output on the serial monitor #define TdsSensorPin A1 // set TdsSensorPin at pin A1 #define temperaturePin 2 // temperature sensor is connected into pin 2 on the Arduino OneWire oneWire(temperaturePin); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) DallasTemperature tempsensor(&oneWire); // Pass our oneWire reference to Dallas Temperature. GravityTDS gravityTds; // define the gravityTds SoftwareSerial Esp8266(5, 6); // Rx, Tx set communication pin for esp8266 to uno WiFiEspClient Esp8266wifi; // set the esp8266 for the mqtt broker connnection PubSubClient client(Esp8266wifi); // set the esp8266 for the mqtt broker connnection unsigned long previousMillis1 = 0; // used to delay without delay the system for sensor data unsigned long previousMillis2 = 0; // used to delay without delay the system for the send data to thingspeak float temperature; // variable to store temperature value int tdsValue; // variable to store tds value float EC; // variable to store EC value char ssid[] = ""; // your network SSID (name) char pass[] = ""; // your network password int status = WL_IDLE_STATUS; // the Wifi radio's status String clientName="ESP-Thingspeak"; //char* topic="channels/<channelID/publish/<channelAPI> char* topic = "channels/1244171/publish/FOZYSFXXS4P6DE5N"; // topic to be published to the thingspeak with channel id and api code char* mqtt_server = "mqtt.thingspeak.com"; // set the server for the mqtt of thingspeak void setup() { Serial.begin(9600); // 9600 is the baud rate for the data to display to the serial monitor Esp8266.begin(9600); //9600 is the baud rate for the srial data connection of esp8266 WiFi.init(&Esp8266); client.setServer(mqtt_server, 1883); // set mqtt broker server and port tempsensor.begin(); // begin temperature sensor library gravityTds.setPin(TdsSensorPin); // set pin tds at declared variable TdsSensorPin gravityTds.setAref(5.0); //reference voltage on ADC, default 5.0V on Arduino UNO gravityTds.setAdcRange(1024); //1024 for 10bit ADC;4096 for 12bit ADC // arduino uno adc level is a 10-bit ADC gravityTds.begin(); //initialization InitWiFi(); //call function to intialize wifi Serial.print("Connecting to "); // display on serial monitor Serial.print(mqtt_server); Serial.print(" as "); Serial.println(clientName); if (client.connect((char*) clientName.c_str())) // connect to the thingspeak with the client name { Serial.println("Connected to MQTT broker"); if (client.publish(topic, "Test send data")) // Test send data to the thingspeak { Serial.println("Testing send data succes"); } else { Serial.println("Testing send data failed"); } } else { Serial.println("MQTT connect failed"); Serial.println("Will reset and try again..."); abort(); } } //this function is only for the initialization of the esp8266 to connect to the network & mqtt and initialize the sensor void loop(){ unsigned long currentMillis = millis(); //timer start checkconnection(); // calling function to check the connection if (currentMillis - previousMillis1 >= 2000) //delay without causing system delay { previousMillis1 = currentMillis; sensordata(); // calling fucntion of the sensor data } if (currentMillis - previousMillis2 >= 2000) //delay without causing system delay { previousMillis2 = currentMillis; senddata(); // calling fucntion to send data // send one set of data in 2 seconds } } void sensordata() { tempsensor.requestTemperatures(); // get temperatures temperature = tempsensor.getTempCByIndex(0); // set variable to the temperature sensor output gravityTds.setTemperature(temperature); // set the temperature and execute temperature compensation gravityTds.update(); //sample and calculate tdsValue = gravityTds.getTdsValue(); // then get the value of TDS EC = gravityTds.getEcValue()/1000; // get EC value Serial.println(temperature); // display sent data Serial.println(tdsValue); Serial.println(EC,3); Serial.println("Data Sent"); } void senddata() { String payload="field1="; // payload to send to thingspeak using mqtt broker payload+=temperature; // field1=temperature&field2=tdsValue&field3=EC&status=MQTTPUBLISH payload+="&field2="; //// field1=26.9&field2=120&field3=0.2&status=MQTTPUBLISH payload+=tdsValue; payload+="&field3="; //// field1=26.9&field2=120&field3=0.2&status=MQTTPUBLISH payload+=EC,3; payload+="&status=MQTTPUBLISH"; if (client.connected()) // if client connected { Serial.println("Sending data "); if (client.publish(topic, (char*) payload.c_str())) // send data to the thingspeak, topic (the channel id and channel api) -- payload is the data from sensor that will be sent to the thingspeak { Serial.println(temperature); // display sent data Serial.println(tdsValue); Serial.println(EC,3); Serial.println("Data Sent"); } else { Serial.println("Publish failed"); } } } void checkconnection() /// check connection if disconnected try to reconnect wifi and mqtt broker { if ( status != WL_CONNECTED) Serial.println("Wifi Disconnected"); { while ( status != WL_CONNECTED) { InitWiFi(); // call function to start wifi // reconnect wifi } } if (!client.connected()) // if mqtt broker disconnected from thingspeak { Serial.println("MQTT Disconnected"); while (!client.connected()) // while mqtt broker disconnected from thingspeak { if (client.connect((char*) clientName.c_str())) // reconnect to the server { Serial.println("MQTT connected"); } else { Serial.println("MQTT connect failed"); Serial.println("Will reset and try again..."); } } } } void InitWiFi() { // check for the presence of the module if (WiFi.status() == WL_NO_SHIELD) { Serial.println("WiFi module not present"); // don't continue // don't continue while (true); //keep looping until it detect esp8266 module } // attempt to connect to WiFi network while ( status != WL_CONNECTED) { Serial.print("Attempting to connect to WPA SSID: "); Serial.println(ssid); // Connect to WPA/WPA2 network status = WiFi.begin(ssid, pass); } // print your WiFi ESP8266 IP address IPAddress ip = WiFi.localIP(); Serial.print("IP Address: "); Serial.println(ip); // print the SSID of the network you're attached to Serial.print("SSID: "); Serial.println(WiFi.SSID()); // print the received signal strength long rssi = WiFi.RSSI(); Serial.print("Signal strength (RSSI): "); Serial.println(rssi); delay (5000); } How to write 3 decimal places data in Thingspeak field Here is an example feed from your channel: "created_at": "2021-06-11T23:09:43-04:00", "entry_id": 96, "field1": "30.56", "field2": "313", "field3": "0.586" There are three decimal places in the last measurement. If that is not sufficient, can you explain in more detail about the measurement that you are concerned about? Share only the parts of the code that relate to that measurement. Then describe what you have tried and what you have observed, and what the desired result is. Then I think we will be able to help you get the result you need. field 3decimal thingspeak
Dayne Gilleland in MATLAB Answers
上次活动时间: 2020-2-3

Is it possible to set up Matlab to compare thing speak field values. Field 4 = 1 and Field 5 = 1 and Field 1 > 4 then delay 30 secounds Alert message " xxxxxxxxx"
Owen Medeiros in MATLAB Answers
上次活动时间: 2019-11-5

Hello, I am trying to write instrument data to a ThingSpeak channel using python. I have installed the urllib package and I am using using the urlopen command to write data. I am able to write data for multiple fields (I have shown t1 as an example but I also have t2, t3), however the rate is inconsistent. More explicitly, the time in between data points varies. I have tried different length delays between events, still inconsistent. Is this because of Thingspeak, or my python script? c1 = 'https://api.thingspeak.com/update?api_key=__________&field4=' t1 = urllib.urlopen(c1+str(temp4)) t1.close() sleep(30)

关于 ThingSpeak

The community for students, researchers, and engineers looking to use MATLAB, Simulink, and ThingSpeak for Internet of Things applications. You can find the latest ThingSpeak news, tutorials to jump-start your next IoT project, and a forum to engage in a discussion on your latest cloud-based project. You can see answers to problems other users have solved and share how you solved a problem.