Results for
I don't understand what the -301 error means when trying to write a field to ThingSpeak. I checked my key and my write ID is OK ... The same program on another Arduino Mega and shield W5100 (but on another channel) works well ... Does anyone have any idea what the meaning of this error code is to know in which direction to look! Thank you
code :
void thingspeak(float t, float h, float units, int lum, int TempInt){
ThingSpeak.setField(1, t);
ThingSpeak.setField(2, h);
ThingSpeak.setField(3, units);
ThingSpeak.setField(4, lum);
ThingSpeak.setField(5,TempInt);
ThingSpeak.setStatus("Update OK: ");
/* écriture des champs dans ThingSpeak */ int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
if(x == 200){
Serial.println(F("Update of ThingSpeak ok."));
} else err(6,x); // error handling
} // end of function thingspeak
How to read a JSON output of another device and put data into thingspeak channel:
Maybe useful for others: just figured out, how to parse a JSON, search for a special entry and enter searched value into thingspeak. For this I used the "Get data from webpage" template. An internet search resolved the access to the UBIBOT-json output at "https://api.ubibot.com/channels?account_key=XXX". This is used as "spcify URL". Having several devices a unique search keyword is needed and added in the template for the "specify target string".
So even if the template is not 100% for JSON abjects, this is a quick and dirty method to read it out and use it for further analysis.
Full code is this:
% TODO - Specify URL of the page to read data from
url = 'https://api.ubibot.com/channels?account_key=yyy';
% TODO - Specify the target string to search in webpage
targetString = 'last_values":"{\"field3\":{\"value\":';
% TODO - Replace the [] with channel ID to write data to: writeChannelID = 666; % TODO - Enter the Write API Key between the '' below: writeAPIKey = 'yxc';
%% Scrape the webpage %% data = urlfilter(url, targetString);
%% Analyze Data %% analyzedData = data;
%% Write Data %% thingSpeakWrite(writeChannelID, analyzedData, 'WriteKey', writeAPIKey);
I want to use a microcontroller and esp8266 to control the relay and home appliance. For example, my water pump needs to be "ON" from 6 am to 10 pm and "OFF" from 10 pm to the next day at 6 am. In this case, I want the thingspeak channel's field to auto-update "1" at 6 am and auto-update "0" at 10 pm. I wonder if there a possibility. If it can be achieved, my esp can receive the latest data to control the relay and appliance.
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(); //initializationInitWiFi(); //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);
}Hi,
I managed to get Thingspeak JSON data from my channel. However, I would like to know if theres any way to convert Thingspeak's JSON string data to decimal. I would really appreciate it if anyone could tell me how to convert it to decimal.
Currently, this is my JSON: { "created_at": "2020-10-08T09:24:00.0000000Z", "entry_id": 1, "field1": "0", "field2": "12", "field3": "1", "field4": "1", "field5": "1", "field6": "1" }
May I know if it is as simple as deleting the ""? For eg,
{ "created_at": "2020-10-08T09:24:00.0000000Z", "entry_id": 1, "field1": 0, "field2": 12, "field3": 1, "field4": 1, "field5": 1, "field6": 1 }
Hello, I want to create a sort of an alert to display the temperature health like in the image below:
i have found this code:
% This script uses the Air Quality Index (AQI) calculated
% in "particulateConcentration" to display the appropriate text associated
% with the index.
% Copyright 2019 The MathWorks, Inc.
readChannelID = yourChannelID;
% TODO - Replace the [] with the Field ID to read data from:
fieldID1 = 1;
% Channel Read API Key
% If your channel is private, then enter the read API
% Key between the '' below:
readAPIKey = yourChannelReadKey;
returnAQI = thingSpeakRead(readChannelID, 'Field', fieldID1,'ReadKey', readAPIKey);
[airCondition, conditionIdx] = returnairhealth(returnAQI);
plotairhealth(airCondition, conditionIdx)
%% Plot Air Health
function plotairhealth(airCondition, conditionIdx)
vertices = [0 0; 1 0; 1 1; 0 1];
faces = [1 2 3 4];
% Use Look Up Table and air health condition to get color for reading
faceColorPatchLUT = [0 0.83 0; 0.44 0.95 0.52; 1 0.98 0.53; 0.95 0.98 0.22; 1 0.39 0.39; 1 0 0];
faceColorPatch = faceColorPatchLUT(conditionIdx,:);
airHealthPatch = patch('Faces',faces,'Vertices',vertices,'FaceColor',faceColorPatch);
hold on
text(0.5,0.5,airCondition,'FontSize',16,'HorizontalAlignment','center')
hold off
% Remove Axis handle
axHandle = airHealthPatch.Parent;
axHandle.YTickLabel = [];
axHandle.XTickLabel = [];
end
%% Air Health Condition
function [airCondition,conditionIdx] = returnairhealth(returnAQI)
airCondition = {'Good';'Moderate';'Unhealthy for Sensitive Groups';'Unhealthy';'Very Unhealthy';'Hazardous'};
aqiLow = [0;51;101;151;201;301];
aqiHigh = [50;100;150;200;300;500];
lutAQI = table(airCondition,aqiLow,aqiHigh,'VariableNames',{'Air_Health','AQI_low','AQI_high'});
conditionIdx = find(returnAQI >= lutAQI.AQI_low & returnAQI <= lutAQI.AQI_high);
airCondition = string(lutAQI.Air_Health(conditionIdx));
end
However, i don't know howto adapt it to my case where i have only 2 cases : if my variable = 0 : the health is good and the color of the box is green else if my viariable = 1 ==> healt is dangerous and the color is red.
Hello, I'm new to thingspeak, i want to combine 4 fields in one chart, i have used the code below
readChannelID = 1408944; % YOUR CHANNEL NUMBER fieldID1 = 1; % YOUR FIELD NUMBER ie 1 to 8 fieldID2 = 3; % my case 1 Temp 2 Humid readAPIKey = '19EJIJW6YBM7VS7N'; [data1, time1] = thingSpeakRead(readChannelID, 'Field',fieldID1,'NumDays',1,'ReadKey', readAPIKey); [data2,time2] = thingSpeakRead(readChannelID, 'Field',fieldID2,'NumDays',1,'ReadKey', readAPIKey); thingSpeakPlotYY(time1, data1, time2, data2,... 'YGrid1','on','YLabel1','% H.R.',... 'YLabel2','*C','XLabel','Fecha y hora',... 'Title','Tempix y Humix ultimas 24 horas');
However, an error occurs saying that the function thingSpeakPlotYY is unrecognized
There is exactly the same tutorial for my topic but I couldn't make it work. It worked like a charm on SMS service but it wasn't on call. Authentication shouldn't be a problem cause it's similar to SMS configuration. The remaining information that I've doubt is the "Body" part. I filled it like:
From={+Twilio number}&To={+myNumber}&Body=CO2 concentration is exceeding the threshold value and being at :%%channel_1372010_field_3%%
And also, the API URL is:
https://api.twilio.com/2010-04-01/Accounts/{My AuthSID}/Calls.json
I replaced my own information on the above items but It didn't make a call at all even when the TimeControl app run it. Hope to get your help.
Hi,
I am currently having this internship which we are required to send sensor data to Thingspeak as well receiving data of '0' or '1' from Thingspeak to remotely control the LED.
We have done sending of sensor values to Thingspeak and I was able to send data of '0' and '1' ( on and off) to Thingspeak using a software called "Mendix". Our job is to control the LED from a mobile app and a web dashboard by pressing a button which sends the data to Thingspeak I have created. I am using REST call API to send data to thingspeak by using these 2 URLs: https://api.thingspeak.com/update?api_key=UHVD1PPGDS2X&field1=0 or https://api.thingspeak.com/update?api_key=UHVD1PPGDS&field1=1
This is the C++ code we used to send sensor values to Thingspeak:
void setWifiMode(void){ u8 tx[]="AT+CWMODE=3\r\n"; u32 num = strlen((char *) tx); xil_printf((char *) tx); ESP32_SendBuffer(&ESP32, tx, num); usleep(100); receiveData(3); }
void connectWifi(void){ u8 tx[] = "AT+CWJAP=\"eee-iot\",\"hWV4IOcKp0JX\"\r\n";
u32 num = strlen((char *) tx);
xil_printf((char *) tx);
ESP32_SendBuffer(&ESP32, tx, num);
usleep(100);
receiveData(30);
}void establishConnection(void){ u8 tx[] = "AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",80\r\n"; u32 num = strlen((char *) tx); xil_printf((char *) tx); ESP32_SendBuffer(&ESP32, tx, num); receiveData(10); }
void cipsend(float temp, u16 co2, u8 light, float humidity){ u8 command[150]; u8 finalcmd[50]; //field1 Ph field2 Temp field3 co2 field4 humidity field5 light sprintf((char*)command, "GET http://api.thingspeak.com/update?api_key=CE8E8ZJNGZM8&field1=0&field2=%d.%02d&field3=%d&field4=%d.%02d&field5=%d\r\n" ,(int) temp_degc,((int) (temp_degc * 100)) % 100,co2,(int) hum_perrh,((int) (hum_perrh * 100)) % 100,light); u32 length = strlen((char*)command); sprintf((char*)finalcmd, "AT+CIPSEND=%d\r\n", (int)length); u32 cmdlength =strlen((char*)finalcmd); xil_printf("Length %d\r\n", length); xil_printf((char *)finalcmd); ESP32_SendBuffer(&ESP32, finalcmd, cmdlength); sleep(1); xil_printf((char *)command); ESP32_SendBuffer(&ESP32, command, length); receiveData(4); }
We are using a FPGA hardware called Zybo if that helps. I will really appreciate it if anyone could guide us on this as we are just students. My teammate is doing this alone while I am doing the mobile app and web dashboard alone as well and it is quite taxing for us to achieve this without any professional help.
Our difficulty right now is that we are unable to receive data '1' or '0' from Thingspeak to our FPGA hardware, Zybo. We are using Pmod ESP32 for wifi communication and we are currently using C++ language.
The timestamp for the ThingSpeak Alerts I create look like this: "Time: 2021-06-01 06-21-45.001 -04:00" Using a dash (-) instead of a colon (:) between the hour and minutes and minutes and seconds seems very non-standard to me. I've always seen it with a colon.
Is there any way to change the dashes in the time part of the stamp to colons so the above looks like 06:21:45.001? (I presume this is set in "HeaderFields" but don't know how to change it.
Thanks.
Through sensors collect the body vitals and upload it on the cloud and anylsis of that body vitals. How to do analysis
Hello everyone! i'm Chung and i am a student. My major is electrical engineering and I'm learning how to use matlab to load flow analysis. i have a problem with my math problem. It is "matlab code for load flow analysis using newton raphson method". Can you help me write a matlab program that calculates the required problem using the newton-raphson method? I hope to get help from everyone.
Thanks you so much!
Is there a way via MQTT to access the talkback. I want to read the talkback variable using MQTT and not REST. I have a ESP8266 which I am logging data, but also have a relay which I want to switch. I am using MQTT to log the data, but don't wanna use REST to access/read the talkback. Hope there is a way which I missed. Thanks so long.
Hello everyone. Yesterday i started my project and now im trying to export data files (CSV) but it is empty. It cointains just the headers and last read (i think). Anyone knows what is happening?
Example CSV exported created_at,entry_id,field1,field2,field3,latitude,longitude,elevation,status 2021-05-26 19:39:23 -03,1,25.00,"43.00
",,,,, 2021-05-26 19:39:39 -03,2,24.80,40.00"
ThingSpeak includes an integration with The Things Stack to support collection of data over a long range network. I made a short presentation for this upcoming conference that shows you how to add the ThingSpeak integration to your Things Stack project. The agenda seems to be filled with other useful IoT talks. Here is the information on the conference:
Discover the next-generation #LoRaWAN deployments at The Things Stack Conference. Explore advanced LoRaWAN features, cloud integrations and the next-generation #IoT devices at #TheThingsConference - TheThings Stack Edition, online on 28 May 2021!
Registrations are now open: – ow.ly/I1PZ30mNt0I
#TheThingsConference #TheThingsNetwork #LoRaWAN
If you go and see something you like, please feel free to share in this discussion.
'nanmean' requires one of the following: Financial Toolbox Statistics and Machine Learning Toolbox
Error in Custom (no starter code) 1 (line 15) avghumidity= nanmean(humidity);
how to remove this error?
Via a particle photon and webhook, i am sending data to THINGSPEAK. The channel indicates entries e.g. 1239 entries but the graphs are empty. Can anyone help me to fix this? Thanks
Hi, I have an AIOT project on vertical farming project. Currently, I am using Thingspeak to store sensor values. I am planning to do the followings:
1) do an analysis on the data collected for each sensors on their max, min and median (50%) to determine that the sensor value is currently ok for the plants. I am aware that Thingspeak is able to calculate these and I am learning about this now.
2) I would like to predict the sensor values collected ( eg temperature/humidity etc). I feel that this is a cool feature to have in my project but I am not sure how do I go about this. For experts in Thingspeak, do you think this is a must have for an internship project on vertical farming and how do I apply this in my project? I am not sure if this is manageable for a single student to do this and I really appreciate it if anyone would guide me along.