Main Content

Results for

Hello,
I want to fetch Data from the openweather API.
I want to fetch the value "day" from the API for every hour (Time Control)
But there is a Problem with indexing. I tried also "{ }" but there is also the same Error:
Dot indexing is not supported for variables of this type. Error in Wettervorhersage von openweather (line 10) temperature_Morgen = temperature.temp.day;
Does anyone have a good solution for indexing?
Code
api_url = 'https://api.openweathermap.org/data/2.5/onecall?lat=XXXX&lon=XXXXX&exclude=alerts&appid=XXXXXXXXXXXXXXX&lang=de&units=metric';
options = weboptions('ContentType','json');
%% Daten von der API abrufen
weather_data = webread(api_url,options);
% Werte für die Felder des ThingSpeak-Channels auswählen
temperature = weather_data.daily(1);
temperature_Morgen = temperature.temp.day;
humidity = weather_data.daily(1);
humidity_Morgen = humidity.humidity;
uvindex = weather_data.daily(1);
uvindex_Morgen = uvindex.uvi;
%Dieser Code berechnet die Summe von drei möglicherweise vorhandenen Regenwerten, die im Abschnitt daily{1}, daily{2} und daily{3} eines Wetterdaten-Structs enthalten sein können.
%Jeder Regenwert wird durch Überprüfung der Existenz des Felds 'rain' im jeweiligen Abschnitt geprüft. Wenn das Feld existiert, wird der Regenwert gespeichert. Andernfalls wird ein Nullwert verwendet.
%Die gespeicherten Regenwerte werden schließlich addiert und in der Variable "rain" gespeichert.
rain = 0;
for i = 1:3
if isfield(weather_data.daily(i),'rain')
rain_Next = weather_data.daily(i);
rain_Next = rain_Next.rain;
rain = rain + rain_Next;
end
end
% Daten an ThingSpeak senden
writeChannelID = XXXXXXXX; % ID des ThingSpeak-Channels
writeAPIKey = 'XXXXXXXXXXX'; % API-Schlüssel des ThingSpeak-Channels
thingSpeakWrite(writeChannelID, [temperature_Morgen, humidity_Morgen, rain, uvindex_Morgen], 'WriteKey', writeAPIKey);
Openweather json
{
{current}
{today}
{daily[{temp{day}}
{temp{day}}
{temp{day}}
{temp{day}}
{temp{day}}
]
}}
Error:
Dot indexing is not supported for variables of this type. Error in Wettervorhersage von openweather (line 10) temperature_Morgen = temperature.temp.day;
forest
forest
Last activity on 22 Mar 2024

i dont send values tu my channel. my log is this
thanks all
Gretings
juan
log.
Fri Mar 3 22:37:20 2023 user.notice root: [IoT.MQTT]:MQTT Publish Case: 1
Fri Mar 3 22:37:20 2023 user.notice root: [IoT.MQTT]:MQTT Publish Parameters
Fri Mar 3 22:37:20 2023 user.notice iot_keep_alive: Internet Access OK: via wlan0-2
Fri Mar 3 22:37:20 2023 user.notice root: [IoT.MQTT]:server[-h]: mqtt3.thingspeak.com
Fri Mar 3 22:37:20 2023 user.notice root: [IoT.MQTT]:port[-p]: 1883
Fri Mar 3 22:37:20 2023 user.notice iot_keep_alive: use WAN or WiFi for internet access now
Fri Mar 3 22:37:20 2023 user.notice root: [IoT.MQTT]:user[-u]: mwa0000029370786
Fri Mar 3 22:37:20 2023 user.notice root: [IoT.MQTT]:pass[-P]: CCHFW9ZV7F0LDW7C
Fri Mar 3 22:37:20 2023 user.notice root: [IoT.MQTT]:pub_qos[-q]: 0
Fri Mar 3 22:37:20 2023 user.notice root: [IoT.MQTT]:cafile[--cafile]:
Fri Mar 3 22:37:20 2023 user.notice root: [IoT.MQTT]:cert[--cert]: /etc/iot/cert/
Fri Mar 3 22:37:20 2023 user.notice root: [IoT.MQTT]:key[--key]: /etc/iot/cert/
Fri Mar 3 22:37:20 2023 user.notice root: [IoT.MQTT]:clientID[-i]: dragino-1fb960
Fri Mar 3 22:37:20 2023 user.notice root: [IoT.MQTT]:remote_id: 2052257
Fri Mar 3 22:37:20 2023 user.notice root: [IoT.MQTT]:pub_topic[-t]: channels/2052257/publish/X7B8RVY2VP7XERPJ
Fri Mar 3 22:37:20 2023 user.notice root: [IoT.MQTT]:decoder: Not Set
Fri Mar 3 22:37:20 2023 user.notice root: [IoT.MQTT]:mqtt_data[-m]: field1=87&status=MQTTPUBLISH
Hello, I am trying to display my Charts in a React Native App but I can't figure out what is the URL that I should use to display it. Any ideas?
Salve, ho appena realizzato la stazione meteo con l'esp8266 ma non riesco a capire come impostare l'ora di roma (it) sul display. Qualcuno può aiutarmi? Grazie.
I want to fit a circle just like the black line drawn in the figure and trying to find its radius. below is the code i am writing but not getting anything significant. kindly help me how to approch this kind of problems
%%---------------------------- matlab code -----------------------------------%%
clear all
clc
% read the image
img = imread('gra.png');
% convert the image to grayscale
img_gray = rgb2gray(img);
% perform edge detection using the Canny algorithm
edge_img = edge(img_gray, 'sobel');
% perform hough transform to detect circles
[centers, radii] = imfindcircles(edge_img, [10 50000],'ObjectPolarity','bright','Sensitivity', 0.95);
% find the largest circle
[max_r, max_i] = max(radii);
max_center = centers(max_i, :);
% plot the results
figure;
imshow(img);
hold on;
viscircles(max_center, max_r, 'EdgeColor', 'b');
Hi,
I'm trying to communicate with my channel ohowever it looks like I'm missing something as my data doesn't appear in the feeds. Below is my code:
#define SW_VERSION " ThinkSpeak.com" // SW version will appears at innitial LCD Display
#define TINY_GSM_MODEM_SIM900
#include <TinyGsmClient.h>
#define SerialAT Serial
TinyGsm modem(SerialAT);
TinyGsmClient client(modem);
/* ESP12-E & Thinkspeak*/
const char apn[] = "xxxxx";
const char user[] = "";
const char pass[] = "";
const char server[] = "api.thingspeak.com";
const int port = 80;
const char* TS_SERVER = "api.thingspeak.com";
String TS_API_KEY ="xxxxx";
int sent = 0;
/* TIMER */
#include <SimpleTimer.h>
SimpleTimer timer;
/* OLED */
#include <ACROBOTIC_SSD1306.h> // library for OLED: SCL ==> D1; SDA ==> D2
#include <SPI.h>
#include <Wire.h>
/* DHT22*/
#include "DHT.h"
#define DHTPIN D3
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
float hum = 0;
float temp = 0;
/* Soil Moister */
#define soilMoisterPin A0
#define soilMoisterVcc D4 //not used. LM393 VCC connect to 3.3V
int soilMoister = 0;
/* DS18B20 Temperature Sensor */
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 14 // DS18B20 on NodeMCU pin D5 corresponds to GPIO 014 on Arduino
float soilTemp;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
void setup()
{
Serial.begin(115200);
delay(10);
Serial.println(".... Starting Setup");
SerialAT.begin(115200);
delay(3000);
// Restart takes quite some time
// To skip it, call init() instead of restart()
Serial.println("Initializing modem...");
modem.init();
pinMode(soilMoisterVcc, OUTPUT);
Serial.begin(115200);
delay(10);
oledStart();
dht.begin();
DS18B20.begin();
timer.setInterval(2000L, getDhtData);
timer.setInterval(7000L, getSoilMoisterData);
timer.setInterval(9000L, getSoilTempData);
timer.setInterval(19000L, sendDataTS);
digitalWrite (soilMoisterVcc, LOW);
}
void loop()
{
displayData();
timer.run(); // Initiates SimpleTimer
}
/***************************************************
* Start OLED
**************************************************/
void oledStart(void)
{
Wire.begin();
oled.init(); // Initialze SSD1306 OLED display
clearOledDisplay();
oled.clearDisplay(); // Clear screen
oled.setTextXY(0,0);
oled.putString(" ");
}
/***************************************************
* Get DHT data
**************************************************/
void getDhtData(void)
{
float tempIni = temp;
float humIni = hum;
temp = dht.readTemperature();
hum = dht.readHumidity();
if (isnan(hum) || isnan(temp)) // Check if any reads failed and exit early (to try again).
{
Serial.println("Failed to read from DHT sensor!");
temp = tempIni;
hum = humIni;
return;
}
}
/***************************************************
* Get Soil Moister Sensor data
**************************************************/
void getSoilMoisterData(void)
{
soilMoister = 0;
digitalWrite (soilMoisterVcc, HIGH);
delay (500);
int N = 3;
for(int i = 0; i < N; i++) // read sensor "N" times and get the average
{
soilMoister += analogRead(soilMoisterPin);
delay(150);
}
digitalWrite (soilMoisterVcc, LOW);
soilMoister = soilMoister/N;
Serial.println(soilMoister);
soilMoister = map(soilMoister, 689, 274, 0, 100);
}
/***************************************************
* Get SoilTemp sensor data
**************************************************/
void getSoilTempData()
{
DS18B20.requestTemperatures();
soilTemp = DS18B20.getTempCByIndex(0);
int newData = ((soilTemp + 0.05) * 10); //fix soilTemp value to 1 decimal place.
soilTemp = (newData / 10.0);
}
/***************************************************
* Display data at Serial Monitora & OLED Display
**************************************************/
void displayData(void)
{
Serial.print(" Temperature: ");
Serial.print(temp);
Serial.print("oC Humidity: ");
Serial.print(hum);
Serial.println("%");
Serial.print("SoilTemp: ");
Serial.print(soilTemp);
Serial.print("oC");
oled.setTextXY(1,0); // Set cursor position, start of line 2
oled.putString("TEMP: " + String(temp) + " oC");
oled.setTextXY(3,0); // Set cursor position, start of line 2
oled.putString("HUM : " + String(hum) + " %");
oled.setTextXY(5,0); // Set cursor position, start of line 2
oled.putString("Tsoil:" + String(soilTemp) + " oC");
oled.setTextXY(7,0); // Set cursor position, start of line 2
oled.putString("Hsoil: " + String(soilMoister) + " %");
}
/***************************************************
* Clear OLED Display
**************************************************/
void clearOledDisplay()
{
oled.setFont(font8x8);
oled.setTextXY(0,0); oled.putString(" ");
oled.setTextXY(1,0); oled.putString(" ");
oled.setTextXY(2,0); oled.putString(" ");
oled.setTextXY(3,0); oled.putString(" ");
oled.setTextXY(4,0); oled.putString(" ");
oled.setTextXY(5,0); oled.putString(" ");
oled.setTextXY(6,0); oled.putString(" ");
oled.setTextXY(7,0); oled.putString(" ");
oled.setTextXY(0,0); oled.putString(" ");
}
/***************************************************
* Sending Data to Thinkspeak Channel
**************************************************/
void sendDataTS(void)
{
if (client.connect(TS_SERVER, 80))
{
String postStr = TS_API_KEY;
postStr += "&field1=";
postStr += String(temp);
postStr += "&field2=";
postStr += String(hum);
postStr += "&field3=";
postStr += String(soilMoister);
postStr += "&field4=";
postStr += String(soilTemp);
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: " + TS_API_KEY + "\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);
delay(1000);
}
sent++;
client.stop();
}
First I get this on my serial monitor:
After some time:
And after some more time:
With my limited knowledge on the subject I can't figure it out.
Any help would be appreciated.
Thanks.
Not able to display password by copying to clipboard or by clicking the unhide icon - have tried multiple computers.
Anyone else had this problem with mqtt?
I am sending my sensor readings to thingspeak channel using raspberrry pi board but i dont know how can we send some instruction back to the raspberry pi board to control an LED or Motor or some other things. Can anyone provide some information about this?
can't connect using the following setting in MQTT explorer
should i modify thiem or it's a must to use MQTTX
please advice
I note that there is a limit of 12 TimeControls per user. Is that only for free and Home users, or for Commercial users too? If the latter, that will put a dent in my plans. I basically want to calculate daily averages and send customers an SMS once per day with their summary data.
I have this message "You have a React with similar Test Frequency, Action, and Option settings. Delete that React to save this one."
But that's not true. It's another channel, another field that must trigger another matlab analysis...........
Any idea on how to unblock this issue?
Thank you
hi, my tracker using A9G always giving incorrect coordinates 999.00.please help

My learning is progressing well. I borrow heavily on examples given on this site. I need to know the correct commands for coding in Matlab analysis. For a simple example, what is the correct code symbol for multiplication? Yes, I know it is (a)*(b). But, is there a glossary of all such? For another example, I tried to generate a random number in Matlab analysis by writing: mu = 1; sigma = 5; rannum = Random (‘Normal’, mu, sigma)

But when I run this code I get the following error message: .....

“random” requires access to one of the following...

Sim Biology or

Statistics & Machine Learning Toolbox...

So, in summary, does my subscription allow such access and/or how do I learn the syntax Matlab requires for code operations?

Thanks.

In the Matlab analysis option on my Thingspeak channel I chose to experiment with the example in the title regarding humidity average. It works fine but only works once. How can I keep it updating every 5 minutes or so?

I am very happy with ThingSpeak. I have a prototype Pico W project that it working well.
I tried 6 other IOT platforms and ThingSpeak was the BEST!
I wrote about my experience here:
Hi all,
I am wondering whats the total cost to use MATLAB for algo trading. The transparent part is of coz the price of matlab and the toolboxes. But I was shocked to find out the APIs to connect to Interactive Brokers are not free (costly in fact!). Is there free API to connect to IB? What other hidden costs are there? I saw the X Trader in the Automated Trading with MATLAB video. Is this XTrader software part of MATLAB toolbox? Do we need to pay additional to Trading Technologies (to use X_Trader). Also what data feed is the most cost effecient? Is there any additional hidden cost that I am not aware of?
Thanks!
Hi
I used to have the following daily max, min and mean code working. But, this week it seems to work for max and mins but not means. Any idea what's going on?
writeAPIKey = 'xxxxxx';
% Define date range of 1 day
end1 = datetime('now')
start=datetime('today')
% Read Weight data from Field1 for last 24 hrs
[Weight, time] = thingSpeakRead(xxxxxx,'DateRange', [start,end1], 'Fields', [1]);
Wtmax = max(Weight); % Get 24hr Max
Wtmin = min(Weight); % Get 24hr Min
Wtav = mean(Weight); % Get 24hr Av
% display results
display(Wtmax, 'Wt_max'), display(Wtmin, 'Wt_min'), display(Wtav, 'Wtav');
Output:
end1 =
datetime
30-Jan-2023 14:00:35
start =
datetime
30-Jan-2023
Wt_max =
-0.0685
Wt_min =
-0.5190
Wtav =
NaN
Good morning,
I am trying to receive a long number in thingspeak and convert it to a string. However, when I receive it, it converts it to a number using scientific notation. I have tried changing the format to long g and others and was able to get rid of the scientific notation part.
After doing so, I have used commands such as num2str, mat2str, and compose to represent the number as a string, but I keep getting results that are off. An example is a message i am sending as:
field1=100630000553400000000
using an MQTT desktop client. However, when I receive it and print the result, I get:
0100630000553399992320
The numbers are close but the right one. Is there something I am missing?
Thanks in advance!
Pedro Ch.
I want to import data from a .cvs with the requested format but constantly the same error comes out : "The uploaded file was not imported because it is missing timestamps."
My data is in this format:
created_at,field1,field2,field3
1600064881,50.818,0,0
Could someone help me fix it?
Thank you
Pedro
Pedro
Last activity on 25 Jan 2023

Hi, what would be the best approach to use the gauge widget to display calculated data? I have a channel that displays a value that needs some math applied to it to give a correct value. I have a matlab visualization that converts this value into what I need and plots it. However, i believe a gauge is more appropriate than a plot and it seems the matlab "uigauge" object does not work for thingspeak.
Is there a way for the gauge widget to show my data coming out of the matlab script?
Thanks!