Main Content

Results for

Edward
Edward
Last activity on 28 Dec 2023

I am sending data to Thingspeak chanels from an ESP8266. I am saving data on the ESP memory which is collected at 5 minute intervals . I have created a trigger function which sends the data on demand in batches from the memory, which means there could be varying number of Data points from say 10 to 50.However I have notice recently whilst my code tells me the data points have been transmitted not all get recorded in thingspeak, are there restrictions which cause this problem and if so what is the solution please?
Hi, while I can download data from the thingspeak page as csv older than 5 months, I can't read history data older than one month.
The data exists on the database.
This are my requests:
https://api.thingspeak.com/channels/667773/fields/1.json?start=2023-11-23T01:01:10.000Z
The same results. Every day the older value date is higher by one day.
Today the older value day is: 2023-11-25T02:13:46Z
Why? Is there a limit to history data loading?
I have encountered a problem. I want to study the direction of PHEVP2 configuration energy control strategy, but the whole vehicle model has stumped me. I don't know how to proceed, and every time I run, an error message will be reported. I don't understand where the problem lies?
Joseph Varani
Joseph Varani
Last activity on 20 Dec 2023

Hello, I have followed the tutorial from https://www.halvorsen.blog/documents/technology/iot/arduino/resources/Arduino%20UNO%20R4%20WiFi%20and%20ThingSpeak.pdf to use an arduino Uno R4 wifi board to write sensor data to thingspeak, and the field 1 of random data is updating properly, but when I try to send data from analog pin A0 it will not update to field 2. I've been speaking with ChatGPT to try to resolve this issue, and it has offered several solutions that have simplified the code dramatically but the same problem persists. I wonder if this could be an error with the channel settings in my thingspeak channel? I cannot find any errors myself. ChatGPT suggested looking for the http responses to trouble shoot and both fields return -210, which it says means the API key is missing, but I have stored this key in the seperate arduino_secrets.h tab in the code, so both fields must be using the same API key, and since field 1 is working properly I don't think this is the issue. This is why I suspect there might be a deeper issue with my channel. I set it up about a year ago with a different experimental project, so maybe it has been corrupted over time. Any help is much appreciated! My current loop code reads as follows:
void loop() {
// Update field 1
float temperature = random(2000, 3000) / 100.0;
Serial.println(temperature);
ThingSpeak.setField(1, temperature);
ThingSpeak.writeFields(SECRET_CH_ID, SECRET_WRITE_APIKEY);
int response = ThingSpeak.writeFields(SECRET_CH_ID, SECRET_WRITE_APIKEY);
Serial.print("ThingSpeak write response code: ");
Serial.println(response);
delay(1000); // Add a delay to separate updates
// Update field 2
float button = analogRead(A0);
int buttonInt = static_cast<int>(button);
Serial.println(buttonInt);
ThingSpeak.setField(2, buttonInt);
ThingSpeak.writeFields(SECRET_CH_ID, SECRET_WRITE_APIKEY);
int response2 = ThingSpeak.writeFields(SECRET_CH_ID, SECRET_WRITE_APIKEY);
Serial.print("ThingSpeak write response code: ");
Serial.println(response2);
delay(19000); // Adjust the delay to maintain the total delay period
}
I have two public channels and this happens in both: when I change the chart type from Line to Column (or any other type), the chart type does not change, the datapoints keep being displayed as a line.
I have cleared both channels but this did not fix the issue. Also, my devices keep uploading the values to Thingspeak normally, it just seems Chart Options isnt working.
Dear all,
in the Matlab Analysis I use twice the fuinction thingSpeakRead to read data from a channel, from two different fields.
The problem is that so far, only one of the values is read properly and the other one delivers NaN.
What could be the reason?
Thank you!
Here's my code:
% TODO - Replace the [] with channel ID to read data from:
readChannelID = [xxx];
% TODO - Enter the Read API Key between the '' below:
readAPIKey = 'xxxxxxxx';
% TODO - Replace the [] with channel ID to write data to:
writeChannelID = [xxx];
% TODO - Enter the Write API Key between the '' below:
writeAPIKey = 'xxxxxx';
%% Read Data %%
%data = thingSpeakRead(readChannelID, 'ReadKey', readAPIKey);
temperature = thingSpeakRead(xxx,Fields=[1])
humidity = thingSpeakRead(xxx,Fields=[8])
Josue
Josue
Last activity on 12 Dec 2023

Hello I want to upload a single value from a raspberry and I can't find a way. Can somebody help me?
Lot of Thanks¡¡
TimeControl Ran, but it didn't appiied it to channel (chart has not been updated in the right time and in the end, it did not ran, had to manually run the script by myself). And I would like to request to MathWorks to fix (modify) my chart to right time and value and investigate this problem.
I want to control the level my water tank with a esp8266 and Thingspeak.
I can see the level in Thingspeak. This is working.
Now I want to send 2 emails :
  1. One daily email with the actual level
  2. Alarm email when level is below a setpoint.
How can I incorporate the value from a channel in the email ?
What I have now for the daily email , but with errors :
alert_body = 'huidig peil regenput';
channelID = ..........;
% Provide the ThingSpeak alerts API key. All alerts API keys start with TAK.
alertApiKey = 'TAK...............';
% Set the address for the HTTTP call
alertUrl="https://api.thingspeak.com/alerts/send";
% webwrite uses weboptions to add required headers. Alerts needs a ThingSpeak-Alerts-API-Key header.
options = weboptions("HeaderFields", ["ThingSpeak-Alerts-API-Key", alertApiKey ]);
% Set the email subject.
alertSubject = sprintf("Niveau regenput " );
% Read the recent data.
peil = thingSpeakRead(channelID,'Fields',1);
% Check to make sure the data was read correctly from the channel.
% Set the outgoing message
webwrite(alertUrl , "body", alertBody, "subject", alertSubject,'Fields',peil);
% Catch errors so the MATLAB code does not disable a TimeControl if it fails
try
webwrite(alertUrl , "body", alert_body, "subject", alertSubject, options);
catch someException
fprintf("Failed to send alert: %s\n", someException.message);
end
The errors I receive :
Unrecognized function or variable 'alert_Body'.
Error in Read Channel to Trigger Email 1 (line 24)
webwrite(alertUrl , "body", alert_Body, "subject", alertSubject,"Fields",peil);
Manny thanks in advance
Andreas
Andreas
Last activity on 9 Dec 2023

Hallo,
ich Neuling hier, und habe das Beispiel WriteMultipleFields benutzt um die Funktionsweise zu verstehen.
So weit so gut, hat auch alles grklappt. Jetzt nach 2 Tagen bekomme ich immer eine Fehlermeldung.
Problem updating channel. HTTP error code -401 abwechselnd mit
Channel update successful.
Es ist immernoch die gleiche Software, Board ist WiFi LoRa 32 V3.
Buongiorno, non mi è possibile connetermi al canale di thingspeak che ho creato, per passare i dati tramite MQTT. Il codice segue la libreria PubSubClient su arduino ide, l'errore restituito dal serial monitor dell'ide é: -4 : MQTT_CONNECTION_TIMEOUT - the server didn't respond within the keepalive time.
Allego il codice per eventuali verifiche:
Grazie per a disponibilità
#include "PubSubClient.h"
#include <ESP8266WiFi.h>
#include "secrets.h"
bool DEBUG = false; // true=serial message of debug enabled
char* server = "mqtt.thingspeak.com";
WiFiClient wifiClient;
PubSubClient client(server, 1883, wifiClient);
String payload;
// BME280 Setting
#include <Wire.h>
#include <Adafruit_BME280.h>
//#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme; // I2C
bool BMEStatus;
ADC_MODE(ADC_VCC); // Set ADC for read Vcc
// Update time in seconds. Min with Thingspeak is ~20 seconds
const int UPDATE_INTERVAL_SECONDS = 3600; //il clock interno ha un errore del 5% questo valore va tarato sperimentalmente
//const int UPDATE_INTERVAL_SECONDS = 60; // caricamento ogni minuto solo per test
void setup()
{
// Connect BME280 GND TO pin14 OR board's GND
pinMode(14, OUTPUT);
digitalWrite(14, LOW);
Serial.begin(115200);
delay(10);
// BME280 Initialise I2C communication as MASTER
Wire.begin(13, 12); //Wire.begin([SDA], [SCL])
BMEStatus = bme.begin();
if (!BMEStatus)
{
if (DEBUG) { Serial.println("Could not find BME280!"); }
//while (1);
}
// Weather monitoring See chapter 3.5 Recommended modes of operation
bme.setSampling(Adafruit_BME280::MODE_FORCED,
Adafruit_BME280::SAMPLING_X1, // temperature
Adafruit_BME280::SAMPLING_X1, // pressure
Adafruit_BME280::SAMPLING_X1, // humidity
Adafruit_BME280::FILTER_OFF );
// read values from the sensor
float temperature, humidity, pressure;
if (BMEStatus)
{
temperature = bme.readTemperature();
humidity = bme.readHumidity();
pressure = bme.readPressure() / 100.0F;
}
else
{
if (DEBUG) Serial.println("Could not find BME280!");
temperature=0;
humidity=0;
pressure=0;
}
float voltage = ESP.getVcc();
voltage = voltage/1024.0; //volt
if (DEBUG)
{
Serial.println("T= " + String(temperature) + "°C H= " + String(humidity) + "% P=" + String(pressure) + "hPa V=" + voltage + "V");
}
// Construct MQTT payload
payload="field1=";
payload+=temperature;
payload+="&field2=";
payload+=humidity;
payload+="&field3=";
payload+=pressure;
payload+="&field4=";
payload+=voltage;
payload+="&status=MQTTPUBLISH";
//Connect to Wifi
if (DEBUG)
{
Serial.println();
Serial.print("\nConnecting to WiFi SSID ");
Serial.print(SECRET_SSID);
}
WiFi.begin(SECRET_SSID, SECRET_PASS);
int timeOut=10; // Time out to connect is 10 seconds
while ((WiFi.status() != WL_CONNECTED) && timeOut>0)
{
delay(1000);
if (DEBUG) { Serial.print("."); }
timeOut--;
}
if (timeOut==0) //No WiFi!
{
if (DEBUG) Serial.println("\nTimeOut Connection, go to sleep!\n\n");
ESP.deepSleep(1E6 * UPDATE_INTERVAL_SECONDS);
}
if (DEBUG) // Yes WiFi
{
Serial.print("\nWiFi connected with IP address: ");
Serial.println(WiFi.localIP());
}
// Reconnect if MQTT client is not connected.
if (!client.connected())
{
reconnect();
}
mqttpublish();
delay(200); // Waiting for transmission to complete!!! (ci vuole)
WiFi.disconnect( true );
delay( 1 );
if (DEBUG) { Serial.println("Go to sleep!\n\n"); }
// Sleep ESP and disable wifi at wakeup
ESP.deepSleep( 1E6 * UPDATE_INTERVAL_SECONDS, WAKE_RF_DISABLED );
}
void loop()
{
//there's nothing to do
}
void mqttpublish()
{
// read values from the sensor
float temperature, humidity, pressure;
if (DEBUG)
{
Serial.print("Sending payload: ");
Serial.println(payload);
}
// Create a topic string and publish data to ThingSpeak channel feed.
String topicString ="channels/" + String( channelID ) + "/publish/"+String(writeAPIKey);
unsigned int length=topicString.length();
char topicBuffer[length];
topicString.toCharArray(topicBuffer,length+1);
if (client.publish(topicBuffer, (char*) payload.c_str()))
{
if (DEBUG) Serial.println("Publish ok");
}
else
{
if (DEBUG) Serial.println("Publish failed");
}
}
void reconnect()
{
String clientName="MY-ESP";
// Loop until we're reconnected
while (!client.connected())
{
if (DEBUG) Serial.println("Attempting MQTT connection...");
// Try to connect to the MQTT broker
if (client.connect((char*) clientName.c_str()))
{
if (DEBUG) Serial.println("Connected");
}
else
{
if (DEBUG)
{
Serial.print("failed, try again");
// Print to know why the connection failed.
// See http://pubsubclient.knolleary.net/api.html#state for the failure code explanation.
Serial.print(client.state());
Serial.println(" try again in 2 seconds");
}
delay(2000);
}
}
}
Quick answer: Add set(hS,'Color',[0 0.4470 0.7410]) to code line 329 (R2023b).
Explanation: Function corrplot uses functions plotmatrix and lsline. In lsline get(hh(k),'Color') is called in for cycle for each line and scatter object in axes. Inside the corrplot it is also called for all axes, which is slow. However, when you first set the color to any given value, internal optimization makes it much faster. I chose [0 0.4470 0.7410], because it is a default color for plotmatrix and corrplot and this setting doesn't change a behavior of corrplot.
Suggestion for a better solution: Add the line of code set(hS,'Color',[0 0.4470 0.7410]) to the function plotmatrix. This will make not only corrplot faster, but also any other possible combinations of plotmatrix and get functions called like this:
h = plotmatrix(A);
% set(h,'Color',[0 0.4470 0.7410])
for k = 1:length(h(:))
get(h(k),'Color');
end
er
er
Last activity on 7 Dec 2023

How to Simulate a Synchronous Compensator in Simulink?

I have been having problems sending ThingSpeak alerts so I created a simple routine that demonstrates the problem. The code executes successfully but I never receive an email with the alert. What am I doing wrong?
% Set Thingspeak address, alerts API key, and options for the HTTTP call
alertUrl = "https://api.thingspeak.com/alerts/send";
alertApiKey = "TAKxxxxxxxxxxxxxxxx";
options = weboptions("HeaderFields",["ThingSpeak-Alerts-API-Key",alertApiKey]);
% Set content for email subject and body.
alertSubject = "ThingSpeak Alert Subject";
alertBody = "ThingSpeak Alert Body";
% Catch errors so the MATLAB code does not disable a TimeControl if it fails
try
webwrite(alertUrl, "body", alertBody, "subject", alertSubject, options);
catch Exception
fprintf("Failed to send alert: %s\n", Exception.message);
end
We are thrilled to announce the grand prize winners of our MATLAB Flipbook contest! This year, we invited the MATLAB Graphics Infrastructure team, renowned for their expertise in exporting and animation workflows, to be our judges. After careful consideration, they have selected the top three winners:
1st place - Rolling fog / Tim
Judge comments: Creative and realistic rendering with well-written code
Judge comments: Festive and advanced animation that is appropriate to the current holiday season.
Judge comments: Nice translation of existing shader logic to MATLAB that produces an advanced and appealing visual effect.
In addition, after validating the votes, we are pleased to announce the top 10 participants on the leaderboard:
Congratulations to all! Your creativity and skills have inspired many of us to explore and learn new skills, and make this contest a big success!
Am running multiple sensors in the field producing strings of data then sending them to a node. The node is an Arduino Uno on which SIM 800 is attached for internet connectivity. After computation, the result is several strings that i want to display to things speak. The code i have so far can only upload numerical data. Am in need of help to display these strings in Thingsspeak.Help me.
Dear Team,
I have populated my data on ThingsBoard platform using ESP8266, now I want to read that data using MATLAB Industrial Communication Toolbox. I have written a code for this purpose below,
% Replace these values with your ThingsBoard MQTT broker details
brokerAddress = "ssl://demo.thingsboard.io"; % Adjust the broker address
port = 1883; % Use the appropriate port for secure MQTT
% Replace these values with your ThingsBoard device details
clientID = "";
userName = "";
password = ""; % Leave empty if not required
% Replace this with the path to the root certificate you downloaded
rootCert = "";
% Create an MQTT client
mqClient = mqttclient(brokerAddress, 'Port', port, 'ClientID', clientID, ...
'Username', userName, 'Password', password, 'CARootCertificate', rootCert);
% Check if the connection is established
mqClient.Connected
% Expected output: ans = int32(1)
% Subscribe to the telemetry topic
topicToSub = "v1/devices/me/telemetry";
subscribe(mqClient, topicToSub);
% Wait for a while to receive messages (adjust the time as needed)
pause(60);
% Peek at the MQTT client to view received messages
peek(mqClient);
% Close the MQTT client
clear mqClient;
%%%%__________________Output Result______________________%%%%%
>> MQTT_Receive
Warning: Using a port that allows unencrypted communication. For confidential matters, considering using an encryption
enforcing port, such as 8883.
Error using MQTT_Receive
Failed to establish a connection with broker "ssl://demo.thingsboard.io".
I desperately seeking your assistance in this regard
The MATLAB Flipbook Mini Hack contest has concluded! During the 4 weeks, over 600 creative animations have been created. We had a lot of fun and a great learning experience! Thank you, everyone!
Now it’s the time to announce week 4 winners. Note that grand prize winners will be announced shortly after we validate votes on winning entries.
Realism:
Holiday & Season:
Abstract:
Cartoon:
Congratulations, weekly winners!We will reach out to you shortly for your prizes.
Looking for an opportunity to practice your AI skills on a real-world problem? Interested in AI for climage change? Sign up for the Kelp Wanted challenge, which tasks participants with developing an algorithm that can detect the presence of kelp forests from satellite images.
Participants of all skill levels from anywhere in the world are welcome to compete!
MathWorks provides the following resources for all participants: