Ege Hassürücü in Discussions
上次活动时间: 2024-3-26

Hello Everyone, I'm running an IoT project at my university using a free . Basically, my system uploads the sensor data to 4 different fields of a ThingSpeak channel and I'm reading from or writing to the channel through Simulink. I have a few questions regarding this topic: I'm trying to upload to the server every 3 seconds (which seemed to be providing the best results so far). Since the channel only accepts data transmit every 15 seconds, what is the optimized upload interval rate to match the interval rate of the channel? Because otherwise I have realized that my interval rate can go up to 1min sometimes for some reason. Is reading from/writing to the channel through simulink while the system is uploading data to the channel slow down th whole process? What is your overall suggestion in this case? I'm excited to hear your suggestions and experiences! Regards, Ege Does reading data from Simulink, slow down my server upload? I would prefer if you can stop trying to update every 3 seconds. This can result in a lot of wasted server time for us. Though your model may be putting other delays in there, Im not sure how to profile your model to be sure. Maybe Ill ask my Simulink firends about model profiling. I do recall having a similar issue with some Simulink models that I had made, Like this solar tracker. I recall there are settings in the model to change the timing to be closer to real time.. But I cannot report the details here off the top of my head. If you figure it out, please let us know here. For #2 are you asking if adding ThingSpeak can impede your model performance? Hi @Christopher Stapels, I solved the issue, thanks for your quick response! Also, reading the data from simulink doesn't seem to be effecting the performance of the channel now so far. The main issue was how i create the http request, in the new version I used your ESP32 library and now I'm able to update every 15.5 seconds. Here are the old and new versions: Old version: void loop() { unsigned long currentMillis = millis(); unsigned long interval = currentMillis - previousMillis; if (interval > UPLOAD_RATE) { // Create HTTP request String http_str = "GET /update?api_key=" + Apikey + "&field1=" + String(messageData1) + "&field2=" + String(messageData2) + "&field3=" + String(messageData3) + " HTTP/1.1\r\n"; http_str += "Host: " + server + "\r\n"; http_str += "Connection: close\r\n\r\n"; if(WiFi.status() != WL_CONNECTED) { Serial.print("Wifi connection failed. Attempting to reconnect..."); connectToWiFi(); delay(5000); } else { Serial.println("Connected to WiFi\n"); // Connect to the ThingSpeak server connectToThingSpeak(); // Make the HTTP request client.print(http_str); client.stop(); previousMillis = currentMillis; // Update the last time the action was performed } } delay(100); } void connectToThingSpeak() { if (client.connect(server.c_str(), 80)) { Serial.println("Connected to ThingSpeak server"); } else { Serial.println("Connection to ThingSpeak server failed"); } } New version: void loop() { unsigned long currentMillis = millis(); unsigned long interval = currentMillis - previousMillis; if (interval > UPLOAD_RATE) { ThingSpeak.setField(1,messageData1); ThingSpeak.setField(2,messageData2); ThingSpeak.setField(3,messageData3); ThingSpeak.setField(4,trialMessage); ThingSpeak.writeFields(CHANNELID,APIKEY); Serial.println("Data uploaded to the ThingSpeak server."); previousMillis = currentMillis; // Update the last time the action was performed } delay(100); } simulink interval read write iot
Andrew Clark in Discussions
上次活动时间: 2023-11-2

Is there a way to get a handle or link to the database each time I do a WRITE or group of WRITEs? I need to access the set of records that comprises a user session, which could be many WRITEs. My impression is that Thingspeak appears as a continuous stream with no way to mark a set of WRITEs as a group or session. Methods I have tried like retrieval (READs) using timestamps and other after-the-fact queries are not very accurate or user friendly. Thanks. How can I track writes or updates to my channel You might consider using the MATLAB datastore type. Also you could set a note in an unused field or in the status and then query for that note or character or session ID. write update record level
Yacine Hammouche in MATLAB Answers
上次活动时间: 2019-5-10

Hello, First of all, sorry for my english, im a french student and my english is far from being perfect. Im trying to transmit location data from an ARDUINO ESP8266 device that has wifi. I stock the lat ant longitude data in field 3 and field 4 after transmetting them. Now, I would like to use matlab to read those data, stocking them into 2 variables, then use thigspeakwrite, to write those variables into location data. I did this code below, it says that is it ok, but the latitude and longitude fields dont change. % Template MATLAB code for reading data from a private channel, analyzing % the data and storing the analyzed data in another channel. % Prior to running this MATLAB code template, assign the channel ID to read % data from to the 'readChannelID' variable. Since this is a private % channel, also assign the read API Key to the 'readAPIKey' variable. You % can find the read API Key in the right side pane of this page. % To store the analyzed data, you will need to write it to a channel other % than the one you are reading data from. Assign this channel ID to the % 'writeChannelID' variable. Also assign the write API Key to the % 'writeAPIKey' variable below. You can find the write API Key in the right % side pane of this page. % TODO - Replace the [] with channel ID to read data from: readChannelID = [123456]; % TODO - Enter the Read API Key between the '' below: readAPIKey = 'AAABBB'; % TODO - Replace the [] with channel ID to write data to: writeChannelID = [123456]; % TODO - Enter the Write API Key between the '' below: writeAPIKey = 'XXXYYY'; %% Read Data %% a= thingSpeakRead(readChannelID,'Fields',[3],'ReadKey', readAPIKey); b= thingSpeakRead(readChannelID,'Fields',[4],'ReadKey', readAPIKey); %% Analyze Data %% % Add code in this section to analyze data and store the result in the % analyzedData variable. %analyzedData = data; %% Write Data %% thingSpeakWrite(readChannelID,'Location',[a,b,3500],'WriteKey','XXXYYY')

关于 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.