Christopher StapelsHans Scharler
Published © MIT

WorkTime Logger Using ThingSpeak and MATLAB® IoT Analytics

IFTTT can write an event based on a geofenced area. Using MATLAB® and ThingSpeak™, the events become a workweek visualization.

BeginnerProtip1 hour1,185
WorkTime Logger Using ThingSpeak and MATLAB® IoT Analytics

Things used in this project

Software apps and online services

MATLAB
MATLAB
Maker service
IFTTT Maker service
ThingSpeak API
ThingSpeak API

Story

Read more

Code

MATLAB code running in ThingSpeak MATLAB analysis

MATLAB
readAPIKey='XXXXXXXXXXXXXXXX'; % Change to your notification channel read API key
writeAPIKey='YYYYYYYYYYYYYYYY'; % Change to your channel write API KEY
myLogChannel=9999999;  % Change to channel ID for the log channel
myStoreChannel=88888888;   % Change to channel ID for the storage channel

startTime=datetime('Today')
todaysData=thingSpeakRead(myLogChannel,'DateRange',[startTime,startTime+days(1)],'Readkey',readAPIKey,'outputformat','timetable');
totalTime=duration(hours(0));
oldTime=datetime();

for index=1:height(todaysData)

    if (string(todaysData.FieldLabel1{index})=="entered")
        oldTime=todaysData.Timestamps(index);
    end
    
    if (string(todaysData.FieldLabel1{index})=="exited")
        currentTime=todaysData.Timestamps(index)-oldTime    
    
        if currentTime>0
             totalTime=totalTime+currentTime; 
        end
    
    end

end

thingSpeakWrite(myStoreChannel,hours(totalTime),'timeStamp',startTime,'writekey',writeAPIKey);

Credits

Christopher Stapels

Christopher Stapels

3 projects • 13 followers
Hans Scharler

Hans Scharler

15 projects • 86 followers
IoT Engineer, Maker - I have a toaster that has been tweeting since 2008.

Comments