3:42 pm

October 29, 2018

Hello, in a ThingSpeak channel, I am reading every one second the information of two current signals (I have the licensed application).
I currently have a MATLAB Analysis routine that adds those two signals and writes, on the same channel, the result of that sum. In the routine I can check that effectively if the sum of the two channels is being done.
I do that now with a good result but my problem is that the channel is not updated except when I run MATLAB Analysis.
How can I make the channel automatically update every second?
-------------------------------------------------------------------------------
This is my routine:
readChannelID = 757632;
readAPIKey = '5SVF05OWH2SVJW4F';
writeChannelID = 757632;
writeAPIKey = 'UY7YXVEC9TID63A1';
%%%%%%%%%%%%%%%%%%%%%% CALCULO DE CORRIENTE %%%%%%%%%%%%%%%%%%%%%%
[Cte1, timeStamp] = thingSpeakRead(readChannelID,'Fields',1,'numPoints', 2, 'ReadKey', readAPIKey);
anyMissingValues = sum(isnan(Cte1));
if sum(anyMissingValues) > 0
missingValueIndex = find(~sum(isnan(Cte1),2));
cleanCte1 = Cte1(missingValueIndex, :);
cleanTimeStamps = timeStamp(missingValueIndex);
else
cleanCte1 = Cte1;
cleanTimeStamps = timeStamp;
end
[Cte2, timeStamp] = thingSpeakRead(readChannelID,'Fields',4,'numPoints', 2, 'ReadKey', readAPIKey);
anyMissingValues = sum(isnan(Cte2));
if sum(anyMissingValues) > 0
missingValueIndex = find(~sum(isnan(Cte2),2));
cleanCte2 = Cte2(missingValueIndex, :);
cleanTimeStamps = timeStamp(missingValueIndex);
else
cleanCte2 = Cte2;
cleanTimeStamps = timeStamp;
end
Corriente = round([cleanCte1 + cleanCte2],1);
display (Corriente, 'Corriente')
%%%%%%%%%%%%%%%%%%%%%% VOLTAJE %%%%%%%%%%%%%%%%%%%%%%
[Voltaje, timeStamp] = thingSpeakRead(readChannelID,'Fields',2,'numPoints', 2, 'ReadKey', readAPIKey);
anyMissingValues = sum(isnan(Voltaje));
if sum(anyMissingValues) > 0
missingValueIndex = find(~sum(isnan(Voltaje),2));
cleanVoltaje = Voltaje(missingValueIndex, :);
cleanTimeStamps = timeStamp(missingValueIndex);
else
cleanVoltaje = Voltaje;
cleanTimeStamps = timeStamp;
end
display (cleanVoltaje, 'Voltaje')
%%%%%%%%%%%%%%%%%%%%%% CALCULO DE POTENCIA %%%%%%%%%%%%%%%%%%%%%%
Potencia = round([Corriente * cleanVoltaje],0)
%%%%%%%%%%%%%%%%%%%%%% CALCULO DE ENERGIA %%%%%%%%%%%%%%%%%%%%%%
[Energia1, timeStamp] = thingSpeakRead(readChannelID,'Fields',3,'numPoints', 2, 'ReadKey', readAPIKey);
anyMissingValues = sum(isnan(Energia1));
if sum(anyMissingValues) > 0
missingValueIndex = find(~sum(isnan(Energia1),2));
cleanEnergia1 = Energia1(missingValueIndex, :);
cleanTimeStamps = timeStamp(missingValueIndex);
else
cleanEnergia1 = Energia1;
cleanTimeStamps = timeStamp;
end
[Energia2, timeStamp] = thingSpeakRead(readChannelID,'Fields',5,'numPoints', 2, 'ReadKey', readAPIKey);
anyMissingValues = sum(isnan(Energia2));
if sum(anyMissingValues) > 0
missingValueIndex = find(~sum(isnan(Energia2),2));
cleanEnergia2 = Energia2(missingValueIndex, :);
cleanTimeStamps = timeStamp(missingValueIndex);
else
cleanEnergia2 = Energia2;
cleanTimeStamps = timeStamp;
end
Energia = [cleanEnergia1 + cleanEnergia2];
display (Energia, 'Energia')
%%%%%%%%%%%%%%%%% Write the results in fields 6, 7 and 8 of the same channel %%%%%%%%%%%%%%%%%%%%
thingSpeakWrite(writeChannelID, 'Fields', [6,7,8], 'Values',...
[Corriente, Potencia, Energia],'WriteKey',writeAPIKey);
5:46 pm


Moderators
March 7, 2017

It will be difficult to get exactly one second, but if you setup a react to run 'on data entry' you might be able to achieve the effect you are looking for.
I would recommend doing a few updates in a batch, rather than every time there is a new entry.
For example, you could read one minute of data or five minutes of data and then update the whole minute of data.
Most Users Ever Online: 166
Currently Online:
18 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
rw950431: 272
Vinod: 240
piajola: 95
turgo: 70
vespapierre: 63
Adarsh_Murthy: 62
Member Stats:
Guest Posters: 1
Members: 8665
Moderators: 1
Admins: 2
Forum Stats:
Groups: 3
Forums: 14
Topics: 1600
Posts: 5760
Newest Members:
Zain-Ul-Abidin, wellbeingcentresuk, Vamsi, frankmehlhop, bhumin, dennysrodialahModerators: cstapels: 460
Administrators: Hans: 405, lee: 457