Roxy in MATLAB Answers
上次活动时间: 2023-5-7

I am trying to collect battery voltage data from arduino parts and upload it from arduino into my Thingspeak channel. So far, I have troubleshot the hardware/wiring aspect, and that doesn't seem to be the issue. At this point, I am assuming the issue is with the code or the Thingspeak channel. Since my arduino board (elegoo arduino Uno R3) is hooked up to my computer using a USB cord, I tried using an HTTP GET request in order to send the information to the Thingspeak channel. I am under a time crunch and am unable to access any kind of Wifi or Ethernet shield, so that is why I am using the USB cord. I could be completely wrong in using the HTTP GET request --I am quite the novice here! Here is the code so far: #include <SoftwareSerial.h> SoftwareSerial Serial1(2, 3); // RX, TX // Define variables float voltage; unsigned long previousMillis = 0; const long interval = 60000; // Upload interval (in milliseconds) String apiKey = "P5LPXSRJT0G4K7VA"; String field = "field1"; String server = "api.thingspeak.com"; String channelID = "2131761"; void setup() { Serial.begin(9600); Serial1.begin(9600); } void loop() { // Read voltage from sensor voltage = analogRead(A0) * 0.0049; // convert analog reading to voltage (0-5V) voltage = voltage * 5.17; // adjust the voltage to reflect the actual voltage // Print voltage to serial monitor Serial.print("Voltage: "); Serial.print(voltage); Serial.println(" V"); // Get current timestamp unsigned long currentMillis = millis(); // Check it's time to upload to ThingSpeak if (currentMillis - previousMillis >= interval) { // Update timestamp previousMillis = currentMillis; // Construct HTTP GET request String getRequest = "GET /update?api_key="; getRequest += apiKey; getRequest += "&"; getRequest += field; getRequest += "="; getRequest += String(voltage); getRequest += "&"; getRequest += "field2=Times"; getRequest += " HTTP/1.1\r\n"; getRequest += "Host: "; getRequest += server; getRequest += "\r\n"; getRequest += "Connection: close\r\n\r\n"; getRequest += "X-THINGSPEAK-CLIENT: arduino\r\n"; getRequest += "Content-Type: application/x-www-form-urlencoded\r\n"; getRequest += "Content-Length: "; getRequest += String(voltage); getRequest += "\r\n"; getRequest += "Host: api.thingspeak.com\r\n"; getRequest += "User-Agent: Arduino/1.0.0\r\n"; getRequest += "\r\n"; getRequest += "\r\n"; getRequest += channelID; // Send HTTP GET request to ThingSpeak via serial communication Serial1.println(getRequest); // Print response from ThingSpeak to serial monitor while (Serial1.available()) { Serial.write(Serial1.read()); } Serial.println(); } delay(1000); } Again, I really have no clue what I am doing here, so I am not surprised if what I have is entirely wrong. Any feedback is greatly appreciated!
Aarya O in MATLAB Answers
上次活动时间: 2022-6-19

I am using the ThingSpeak library to import public weather data, and I wanted to tabulate this data as a matrix. I have copied my code and the output below: data = thingSpeakRead(12397,'Fields',[1,4],NumPoints=50,OutputFormat='TimeTable') data = 50×2 timetable Timestamps WindDirectionNorth0Degrees TemperatureF ____________________ __________________________ ____________ 18-Jun-2022 19:30:23 105 60.5 18-Jun-2022 19:31:23 210 60.5 18-Jun-2022 19:32:23 92 60.7 18-Jun-2022 19:33:23 148 60.5 18-Jun-2022 19:34:23 192 60.5 18-Jun-2022 19:35:23 162 60.7 18-Jun-2022 19:36:23 118 60.7 18-Jun-2022 19:37:23 171 60.7 18-Jun-2022 19:38:23 145 60.7 : : : 18-Jun-2022 20:11:23 160 59.8 18-Jun-2022 20:12:23 174 59.6 18-Jun-2022 20:13:23 182 59.5 18-Jun-2022 20:14:23 112 59.5 18-Jun-2022 20:15:23 205 59.3 18-Jun-2022 20:16:23 196 59.3 18-Jun-2022 20:17:23 158 59.3 18-Jun-2022 20:18:23 158 59.3 18-Jun-2022 20:19:23 152 59.1 How can I import the data so that each category of data populates a column in a larger matrix? I am looking to create a matrix with WindDirectionNorth0Degrees in one column (this is Field 1), and TemperatureF in another column (this is Field 2), so that I can later plot these two against each other to analyze trends. Thank you all for your time.
Daniel Nouri in MATLAB Answers
上次活动时间: 2021-8-7

I exported my channel feed to CSV format, deleted the channel feed data, then tried to import the CSV back into the channel without making any modification to the CSV file. I recieve the error "The file was not uploaded because it contains duplicate timestamps. See Channel Data Import for more information." I have confirmed that there is no duplicate timestamp data in the CSV. This seems to have been an issue in the past: https://www.mathworks.com/matlabcentral/answers/506094-can-t-import-csv-file-into-thingspeak How can I upload the CSV data back into the channel? Thanks!
Aniket Manjare in MATLAB Answers
上次活动时间: 2020-12-20

i am trying to run this code but is not working can you please help me with this %% %Data Collection and Labeling clc; clear all; labelPoints = {[2,50],[51,80]}; NoOfFailureModes = 2; estimateRULFlags = [false, true]; path = 'Datasets/'; labels = {[categorical("OFF"),categorical("ON"),categorical("DUCT BLOCKAGE")],[categorical("OFF"),categorical("ON"),categorical("ROTOR IMBALANCE")]}; rawdata = cell(NoOfFailureModes); data = cell(NoOfFailureModes); for i = 1:NoOfFailureModes rawdata{i} = readtable([path 'Dataset' num2str(i) '.csv'],'Delimiter',','); %Read the downloaded csv file data{i} = dataParsing(rawdata{i},labelPoints{i},labels{i},i); %Parse the rawdata end function data = dataParsing(rawdata,labelPoints,labels,dataset) bias = 44; noOfDataPoints = length(rawdata.entry_id); labelPoints = [0 labelPoints noOfDataPoints]; for i = 1:length(labelPoints)-1 Label(labelPoints(i)+1:labelPoints(i+1),:) = labels(i); %Create Labels for the data points end j = 1; if(dataset == 2) offset = 0; else offset = 2000; end for i = 1:noOfDataPoints text1 = strsplit(rawdata.field1{i},','); text2 = strsplit(rawdata.field2{i},','); text3 = strsplit(rawdata.field3{i},','); text4 = strsplit(rawdata.field4{i},','); text5 = strsplit(rawdata.field5{i},','); text6 = strsplit(rawdata.field6{i},','); var = zeros(length(text1)-1,6); flag = true; for k = 1:length(text1)-1 %to neglect the last comma, use -1 var(k,1) = str2num(text1{k})-bias; var(k,2) = str2num(text2{k})-bias; var(k,3) = str2num(text3{k})-bias; if(var(k,1) ~= -bias || var(k,2) ~= -bias || var(k,3) ~= -bias ) %Turning the device off and on will reset the first data set to all zeroes var(k,4) = str2num(text4{k})-bias; var(k,5) = str2num(text5{k})-bias; var(k,6) = str2num(text6{k})-bias; else flag = false; break; end end if(flag) %accept a valid datapoint data.Label(j,:) = Label(i); data.sno(j,:) = rawdata.entry_id(i) + offset; data.X(j,:) = [var(:,1);var(:,4)]; data.Y(j,:) = [var(:,2);var(:,5)]; data.Z(j,:) = [var(:,3);var(:,6)]; j = j+1; end end data = struct2table(data); end
Håkon Dahle in MATLAB Answers
上次活动时间: 2019-11-27

I have a bunch of files with hourly data that I need to upload into several ThingSpeak Channels. The CSV-files are formatted according to https://se.mathworks.com/help/thingspeak/channel-data-import.html, and look like this (each file is about 8000 lines): datetime,field1,field2 2019-03-31 00:00:00 UTC,43, 2019-03-31 01:00:00 UTC,47, 2019-03-31 02:00:00 UTC,61, 2019-03-31 03:00:00 UTC,68, 2019-03-31 04:00:00 UTC,85, However the upload fails,ThingSpeak claims that there are duplicate data in the CSV file (at this point it would have been super-useful if ThingSpeak could tell me which line had duplicated data, but I had to figure that out by myself - please consider this a feature request!). Anyway after a while I figured out that the problem was related to the date "2019-03-31". I suddenly understood why - this is the day Daylight Savings Time starts. So, by removing EITHER the line 02:00 or the line 03:00 then the upload works. This sort of makes sense: when daylight savings time starts the clock is advanced from 0200 to 0300, so 0200 and 0300 is actually the same point in time and hence they are overlapping data. BUT: I am using UTC which does not use daylight savings time - the whole point of UTC is to provide a constant reference. Hence, my time series above should not fail when doing a data import. Try it yourself: create an empty Thingspeak channel, copy/paste the above lines into a file, upload it. It fails. Now try with either 0200 or 0300 deleted. It works. I could of course write a script that adjusts all times by one hour from March 31 to October 27, but it seems to me that ThingSpeak/Matlab should handle this by properly supporting UTC?

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