Rajendra in MATLAB Answers
上次活动时间: 2025-3-7

i have to paste the url generated in the output ide everytime to get the data on my thingspeak channel: e,g.: http://api.thingspeak.com/update?api_key=***REDACTED***&field1=27.25&field2=3.27&field3=0.00 my code is : #include "DHT.h" #define DHTPIN 15 // Pin where DHT sensor is connected #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE); #define THINGSPEAK_API_KEY "***REDACTED***" #include <SoftwareSerial.h> #include <OneWire.h> #include <DallasTemperature.h> #include <ArduinoJson.h> SoftwareSerial myserial(10, 11); // RX, TX for GSM communication // Temperature Sensor Setup #define ONE_WIRE_BUS 5 OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); // Flow Sensor Setup #define SENSOR_PIN 2 volatile byte pulseCount = 0; float flowRate = 0.0; unsigned int flowMilliLitres = 0; unsigned long totalMilliLitres = 0; unsigned long oldTime = 0; float calibrationFactor = 5.5; // Calibration factor for flow meter // Turbidity Sensor Setup int turbiditySensorValue; float voltage; // Variables for DHT sensor float temperatureC; float temperatureF; void setup() { Serial.begin(9600); myserial.begin(9600); pinMode(SENSOR_PIN, INPUT); digitalWrite(SENSOR_PIN, HIGH); pulseCount = 0; flowRate = 0.0; flowMilliLitres = 0; totalMilliLitres = 0; oldTime = 0; attachInterrupt(digitalPinToInterrupt(SENSOR_PIN), pulseCounter, FALLING); sensors.begin(); // Initialize temperature sensor dht.begin(); // Initialize DHT sensor // GSM Initialization with better error checking initGSM(); } void initGSM() { Serial.println("Initializing GSM..."); // Wait for GSM module to respond while (!sendATCommand("AT", "OK", 1000)) { Serial.println("Waiting for GSM module..."); delay(1000); } sendATCommand("AT+SAPBR=3,1,\"Contype\",\"GPRS\"", "OK", 2000); sendATCommand("AT+SAPBR=3,1,\"APN\",\"your_apn\"", "OK", 2000); // Change APN if needed sendATCommand("AT+SAPBR=1,1", "OK", 2000); sendATCommand("AT+SAPBR=2,1", "OK", 2000); } bool sendATCommand(const char* command, const char* expected_answer, unsigned int timeout) { Serial.println("Sending command: " + String(command)); myserial.println(command); String response = ""; unsigned long previous = millis(); while (millis() - previous < timeout) { while (myserial.available()) { char c = myserial.read(); response += c; } if (response.indexOf(expected_answer) >= 0) { Serial.println("Response: " + response); // Print full response return true; } } Serial.println("Timeout! No response or unexpected response: " + response); return false; } void loop() { flowMeter(); temperature(); turbidity(); sendToThingSpeak(); delay(15000); // 15 second delay between readings } void flowMeter() { if ((millis() - oldTime) > 1000) { detachInterrupt(digitalPinToInterrupt(SENSOR_PIN)); flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor; oldTime = millis(); flowMilliLitres = (flowRate / 60) * 1000; totalMilliLitres += flowMilliLitres; Serial.print("Flow rate: "); Serial.print(flowRate, 2); // Print with 2 decimal places Serial.println(" L/min"); pulseCount = 0; attachInterrupt(digitalPinToInterrupt(SENSOR_PIN), pulseCounter, FALLING); } } void pulseCounter() { pulseCount++; } void temperature() { sensors.requestTemperatures(); temperatureC = sensors.getTempCByIndex(0); temperatureF = sensors.toFahrenheit(temperatureC); Serial.print("Temperature: "); Serial.print(temperatureC); Serial.println("°C"); } void turbidity() { turbiditySensorValue = analogRead(A0); voltage = turbiditySensorValue * (5.0 / 1024.0); Serial.print("Turbidity Voltage: "); Serial.println(voltage, 2); // Print with 2 decimal places } void sendToThingSpeak() { // Check if GSM is connected if (!sendATCommand("AT+SAPBR=2,1", "OK", 2000)) { Serial.println("GSM Network Issue! Not sending data."); return; } // Close any existing HTTP connection sendATCommand("AT+HTTPTERM", "OK", 1000); delay(1000); // Initialize HTTP service if (!sendATCommand("AT+HTTPINIT", "OK", 2000)) { Serial.println("HTTP init failed"); return; } sendATCommand("AT+HTTPPARA=\"CID\",1", "OK", 1000); // Construct URL properly String url = "http://api.thingspeak.com/update?api_key="; url += THINGSPEAK_API_KEY; url += "&field1=" + String(temperatureC); url += "&field2=" + String(voltage); url += "&field3=" + String(flowRate); Serial.println("Generated URL: " + url); // Print full URL before sending // Send URL parameter properly String command = "AT+HTTPPARA=\"URL\",\"" + url + "\""; if (!sendATCommand(command.c_str(), "OK", 2000)) { Serial.println("Setting URL failed"); return; } // Start HTTP GET request if (!sendATCommand("AT+HTTPACTION=0", "+HTTPACTION: 0,200", 5000)) { Serial.println("HTTP GET command failed"); return; } delay(5000); // Wait for response // Read HTTP response if (!sendATCommand("AT+HTTPREAD", "OK", 5000)) { Serial.println("Failed to read HTTP response"); return; } Serial.println("Data sent successfully!"); // Close HTTP connection sendATCommand("AT+HTTPTERM", "OK", 1000); }
Julian in Discussions
上次活动时间: 2024-11-18

Hello, I am wondering why I have over 12000 messages (writes)per day to a channel which I only update all 8 fields every 20 minutes. Or are these statistic timely delayed? Since testing I might have more writes, but now with my ready weather station only every 20 minutes my data will be updated. Wetterbox Channel ID: 2391212 Access: Public Can you explain this to me? Thank you for your help. Regards, Julian Too many messages per day, free account If I read your channel, I see 71 messages from today, and 87 messages from yesterday. howMany=size(thingSpeakRead(2391212 ,"numdays",1, "outputformat","timetable"),1) howManyTwoDay=size(thingSpeakRead(2391212 ,"numdays",2, "outputformat","timetable"),1) howManyTwoDay-howMany=howManyYesterday The total number of messages in your channel right now is about 12,000. I read 8000 of them, the first date in the last 8000 readings is Feb 27 2024. By any chance, are you exporting the data in the channel, clearning your channel and re-importing the data into your channel? Once you update a channel, you use a message. Clearing the channel and reimporting the data just results in double the usage. If you do the clear & re-import "n" times, you are just using "n" times more messages. Thanks for this explanation. True during my testing phase I needed clear and upload data again. This makes sense. Good to know, i'll need to test messages channel update free account
Adithya T G in Discussions
上次活动时间: 2024-5-2

I have noticed that any of thingspeak channels (irrespective of Public or private) can be read by using below request. https://api.thingspeak.com/channels/{channel_ID}/fields/field1/last.html this reduces the security of the channel. If the channel is Private without the valid Read key it should not be able to read from the channel. Am i missing something?? RETRACTED: Thingspeak channels can be read without API Keys. this is not secure! retracted here: https://www.mathworks.com/matlabcentral/answers/2112101-insecure-private-channels?s_tid=prof_contriblnk channel security
Frederic Lhoest in Discussions
上次活动时间: 2024-1-11

Dear Community, Since few weeks it looks like I have lost the ability to move cards order in the channel view. I used to be able to to so. I tried with different browser and even on mobile and it does not work anymore. Did missed something ? Is this feature been removed ? Thanks. Moving / Rearranging cards order same here... https://www.mathworks.com/matlabcentral/discussions/thingspeak/838555-changing-chart-type-from-line-to-any-other-doesn-t-produce-an-effect-anymore?s_tid=srchtitle I have been experiencing the same problem, i think it started almost a month ago Thanks @AIRFLUX. Ive been cross posting that one a lot. Appreciate the assist. Please feel free to chime in on any other discussions here - getting a little bigger crowd would be nice. channel ui cards moving
Gcobani Mkontwana in MATLAB Answers
上次活动时间: 2023-9-4

Hi Team I am trying to read API key to my channel, using jquery to get JSON response to my channel. Here is my jquery logic, i am unable to get a response to my channel i have created and i want to read one field from my channel (field8) only. <script src="https://code.jquery.com/jquery-3.3.1.js"integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="crossorigin="anonymous"></script> <script type="text/javascript"> function loadData(){ var id; //get the data from thingspeak. $.getJSON('https://api.thingspeak.com/channels/899906/fields/8.json?api_key=F35GLOFJ8L99D0OM&results=2',function(data) { id = data.field8; if(id){ displayData(id); } }); } </script>
Alex Ramirez in MATLAB Answers
上次活动时间: 2023-5-1

I used the matlab tutorial to send an image to thingspeak using an ESP32-cam. See link: https://www.mathworks.com/help/thingspeak/write-image-to-thingspeak-from-esp32-camera-board.html The image is being shown using the display widget. I want to use the image for object detection. I set up a new reaction so when a new image is uploaded then a matlab code runs to detect if a certain object is in the image. I can't figure out how to access the actual image data. Using thingSpeakRead() does not work using the image channel id and API key. It does work on the data channels ID and API key but it does not have any data in it. I am not sure how thingspeak can show my image and routinely update with a new image yet I can't use it for matlab analysis. I spoke with a thingspeak rep and they are not sure how to solve this issue. I have a paid student thingspeak account and am using Matlab version R2023a. Any ideas are appreciated.
Camilo Rada in MATLAB Answers
上次活动时间: 2023-3-15

Hi, I'm querying status updates of a channel as part of my workflow. Each of these status updates comes with a "created_at" timestamp, so when I query for the last one I expect to get the latest. However, twice during March I got an status update with a "created_at" timestamp several weeks in the future, which completely messes my workflow. Because that same message always get returned as the latest for several weeks. I could code a workaround for this, but I would rather understand why this happen and how to avoid it. Attached is a CSV export from that channel, and you can see how all dates make sense and suddenly, the entry_id 502 (row 503), reports being created on March 29 2023, 20 days ahead of when it was actually created. Some background to my question: The reason why the status updates are so important in my workflow, is because I'm sending data in binary format (bitpacked) to ThingSpeak from a satellite modem (RockBlock), were a React scripts decode it and send it to another Channel for visualization. One of my encoded messages looks like "6ae5c7c895ec7803abc602c0ffffffffff07a8" To get this encoded messages, I read the status updates of the channel. Due to the way the satellite system works, in the status update I can find the IMEI of the modem, a message ID and the encoded message, therefore one status entry at the status updates feed of the channel looks like this: 300434066310190,1121,6ae5c7c895ec7803abc602c0ffffffffff07a8 So I use these status updates to retreive the binary messages.
rene in Discussions
上次活动时间: 2022-12-6

hello, how i can show module image in to public view. in widget public dont show the option. exist any code for MATLAB? show channel image in public view Right now, images can only be shown on the private view of your channel. There are functions to read images into MATLAB planned for a future release. hi thank you, i can ask here about email notify, im trying add a alert when new image is upload. but maybe is not possible whith no MATLAB functions. i see another options for external email or sms i need study. There is an email alerts service built in to ThingSpeak, but Id prefer you ask a new question about it, specifically asking what you would like to do. It would probably be better to use the MATLAB answers section below unless you are looking to start a borad discussion about the feature and your project. image channel public view matlab
Peter Kellner in MATLAB Answers
上次活动时间: 2021-12-14

In the READ calls for the REST API, there is no mention in the docs for start and end what timezone these are in. My guess is it's either in the timezone of the device, or GMT but it does not explicitly say. I tried setting the timezone to GMT using the timezonep parameter, but then I get no results at all. Here is my encoded string with the auth XXX'd out. https://api.thingspeak.com/channels/1330583/feeds.json?api_key=XXX&timescale=1440&results=100&fields=pm2.5_24hour,name&timezone=Etc%2FUTC&start=2021-11-10%2014:28:48&end=2021-12-10%2014:28:48 Doc I'm reading: https://www.mathworks.com/help/thingspeak/readdata.html
Jaewoo Lee in MATLAB Answers
上次活动时间: 2021-11-9

Hi all, Thanks for looking at my question. I was wondering how to connect different emails to different channels. I plan to create multiple channels for multiple devices at multiple locations (e.g., stores). I would like ThingSpeak to individually send alert notifications to each location manager. For example, I want to make sure that the email notification of channel A is sent only to the manager's email of the location connected to the channel, but not to me (i.e., the account owner's email). Thanks again.
Boyan Biandov in MATLAB Answers
上次活动时间: 2021-10-12

Hi everyone, My use case is pretty simple, I have a channel and need to know each time when the channel URL is hit, for example GET https://api.thingspeak.com/channels/21614/fields/1.json?api_key=XXX&results=1 Is there an internal log that can be retrieved or is there a way to inject a webhook that fires (updating a log engine) each time the channel URL receives an HTTP request? The reson should be easy to figure out - analytcs, I want to see where the requests are coming from, headers, volume and when (date/time). Thank you
MathWorks Support Team in MATLAB Answers
上次活动时间: 2021-8-26

How do I view the "Data Export" button in the privately shared channel in ThingSpeak? This button is available for Public Channels i.e., channels shared with "Share channel view with everyone" option. But the button is not available for privately shared channel i.e., "Share channel view only with the following users" option. How can I save the feed as a CSV for privately shared channel? kA00Z000000oTKvSAM 000092334
Danielle Honigstein in MATLAB Answers
上次活动时间: 2021-5-5

Hi all, I read the data from my channel using thingSpeakRead, but the status of the channel doesn't seem to be available. How do I read that from Matlab (not using REST or MQTT)? EDIT: Code I am using: lastData = thingSpeakRead(channelID,'OutputFormat','TimeTable','ReadKey','MY_READ_KEY') What is printed out: lastData = 1×5 timetable Timestamps AppName Action Address Version Extra ______________ ______________ _________ _________ _________ ____________ 04-May-2021 14:09:25 {'Data1'} {'Data2'} {'Data3'} 3.2 {'Data4'} I would have expected a column of "Status", as my channel has the status enabled. It is not one of the fields, it was from enabling "Show Status" in the channel settings. Thanks, Danielle
Lemuel Aldwin Garcia in Discussions
上次活动时间: 2021-2-3

Hi, I would like to export data from my channel. My channel receives data every 15 minutes but I would like to export the data similar to what I can see when I change the chart/field's timescale to 60 minutes. Thanks! How to export a time-scaled data You can use the API to export data on a 60 minute timescale. Have a look at the query string parameters in the <https://www.mathworks.com/help/thingspeak/readdata.html read data> call, for example sum, timescale, and average. You can use json, xml, or csv data formats for the exported data. data export channel timescale
DL KA in MATLAB Answers
上次活动时间: 2020-12-11

Using the REST API, I would like to be able to query for the number of records of data stored in a ThingSpeak channel before reading that data. Is there a way to do this?
Julien Jacquemet in MATLAB Answers
上次活动时间: 2020-2-22

Hi, I have some difficult to post data on channel. For exemple, I have create a channel test ( visible on https://thingspeak.com/channels/959736 ) The AP KEY for writing is : XXX The AP KEY for reading : YYY When I try to make GET or POST request (from Chrome or Postman) the result is always 0. I use this URL : https://api.thingspeak.com/update?api_key=XXX&field1=5 and I get 0. I didn't understand why, I follow too tutorial and try with Postman but always 0. Thanks for your help. Besy Regards
Emilio Rubio Garcia in MATLAB Answers
上次活动时间: 2020-1-21

Dear Mr.: I've got problem for uploading data to my channe. I am not been able to post (via Get sentence) in my channel (949075) for trials, although I'm getting the right answer from your server. I can see that data is not uploading because it is not appearing in downloaded files. I have been able to post (same Get way) but I had to change Arduino sketch because it was not stable. Is now that it is stable, because I am getting the right sequence of messages from your server. It took a lot of time and trials before I have been able to upload data. Could you, please, help me for solving issue? Please, let me know if I should do anything by my side. Thank you very much in advance. Emilio Rubio.
Gcobani Mkontwana in MATLAB Answers
上次活动时间: 2019-11-5

Hi Is there anyone who can me help with work around example, as to how to publish message using talkback or plugin on client side? I am using native javascript with jquery and have API key sending GET protocol. I want my button to subscribe to that channel i created, please help me by showing an example i am sure can able to do this. My channel have two fields temp and illuminance, both been programmed on IDE Arduno and have button_state that must read from my talkback functionality; Plugin functionality for my button to read or subscribing my channel; <html> <head> <!-- NOTE: This plugin will not be visible on public views of a channel. If you intend to make your channel public, consider using the MATLAB Visualization App to create your visualizations. --> %%PLUGIN_CSS%% %%PLUGIN_JAVASCRIPT%% </head> <body> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"><br/> <div class="col-md-4 text-center"> <button id="singlebutton" name="singlebutton" class="btn btn-primary">IOT-Talk</button> </div> </body> </html> <script src="https://code.jquery.com/jquery-3.3.1.js"integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="crossorigin="anonymous"></script> <script type="text/javascript"> function OPENDOOR() { $.ajax({ url:"https://api.thingspeak.com/talkbacks/35734/commands?key=MF710NTKMG0E44UG&command_string=OPENDOOR&position=1", type: 'GET', success: function(data) { //called when successful //console.log(data); $('#singlebutton').on('click', function (e) { $('#singlebutton').append(data); }) } }); } </script>
www in MATLAB Answers
上次活动时间: 2019-9-16

Hello, I want to run code with the data I get from a channel...How could I do it? Thanks.

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