March 11, 2019
I encountered a problem with my thingspeak data. I want to get the absolute humidity values out of temperature and relative humidity and automatically write the data to the same channel. So i set up a code and a timecontrol where it runs the code every 15 minutes. The problem is that it often displays the value "3072" and it seems like it happens inbetween the times the code is supposed to run. i attached a screenshot of how it looks like. I also cant run the code more often because the minimal periods are 5 minutes and the error occures even if i do that. I think it has to do with the sensors i use transmitting data at a set time (e.g. every 2 minutes) and if theres no data from the Code during that moment it turns into 3072. Im thankfull for any help.
readChannelID = *******;
readAPIKey = '****************';
T = thingSpeakRead(readChannelID, 'Fields',1, 'ReadKey', readAPIKey,'NumMinutes',120)
rF = thingSpeakRead(readChannelID, 'Fields',2, 'ReadKey', readAPIKey,'NumMinutes',120)
BrF = ~isnan(rF);
IndicesrF = arrayfun(@(x) find(BrF(:, x), 1, 'last'), 1:size(rF, 2));
rF = arrayfun(@(x,y) rF(x,y), IndicesrF, 1:size(rF, 2));
BT = ~isnan(T);
IndicesT = arrayfun(@(x) find(BT(:, x), 1, 'last'), 1:size(T, 2));
T = arrayfun(@(x,y) T(x,y), IndicesT, 1:size(T, 2));
aF = (6.112*exp((17.67*T)/(T+243.5))*rF*18.02)/((273.15+T)*100*0.08314)
aFaR = round(aF,2)
writeChannelID = ******;
writeAPIKey = '******************';
thingSpeakWrite(writeChannelID, 'Fields',,'Values',aFaR, 'WriteKey', writeAPIKey)
March 7, 2017
I would definitely recommend setting up a second channel to hold the results. If your device (or something else) is writing values to the same channel, then may collide with the writes from your analysis. That may be why you aren't allowed to write as often as you wish.
For the calculation, I did some simulation and algebra but I wasnt able to fins a solution that leads to 3072. I would also record the values of rF and T that you read to make sure they are coming as you expect. Once you debug the problem, you can remove them.
You could use
thingSpeakWrite(writeChannelID, 'Fields',[4 5 6],'Values',[aFaR, rF,T], 'WriteKey', writeAPIKey)
Last, instead of two reads at the top, I recommend using a timetable.
The first example shows the format you can use:
data = thingSpeakRead(12397,'Fields',[1,4],'NumMinutes',3,'OutputFormat','table')
Then you can use dot notation and the field names.
Most Users Ever Online: 166
Currently Browsing this Page:
Guest Posters: 1
Newest Members:Matthewdupreez1, sbhunu, pabcstar, johnhutcheson1, madhuhada, dayne
Moderators: cstapels: 460
Administrators: Hans: 405, lee: 457