Closed whaleygeek closed 8 years ago
This is the next task I expect to work on now that regular reports are being received from 1 adaptor. The plan is to just append and flush data to a csv file with headings of the PARAM names, for every energy report received. This data log file can then be tail -f monitored or watched by other processes that do things with the data.
I'm not sure yet what to do about multiple devices, I might interleave them with sensorid's inside this log file. But note that the column format will be fixed, so if a switch change message comes in, probably the last known energy data at that point in time will be copied into the energy records. Probably a type field that indicates the type of message received that initiated the record being written, so that switch change messages and energy update messages can easily be differentiated, even in a single flat table design.
There is now a feature in this standard build that logs all messages to energenie.csv. If the file does not exist, it creates it with the headings. If the file does exist, it just appends to it. The flags column has a '1' for any field that is present, and '0' for any that is absent. The code is configured to turn the switch on and off every 60 seconds.
Here's a sample data log
timestamp,mfrid,prodid,sensorid,flags,switch,voltage,freq,reactive,real 1444239056.63,4,2,1675,11111,1,235,49.94921875,-5,8 1444239066.59,4,2,1675,11111,1,235,49.8984375,-4,6 1444239076.59,4,2,1675,11111,1,235,49.8984375,-4,7 1444239096.6,4,2,1675,11111,1,235,49.94921875,-4,7 1444239106.56,4,2,1675,11111,1,235,49.8984375,-4,6 1444239110.34,4,2,1675,10000,0,None,None,None,None 1444239116.55,4,2,1675,11111,0,235,49.94921875,0,2 1444239126.55,4,2,1675,11111,0,234,49.8984375,2,0 1444239136.54,4,2,1675,11111,0,233,49.8984375,0,0 1444239146.52,4,2,1675,11111,0,233,49.8984375,2,0 1444239156.51,4,2,1675,11111,0,235,49.8984375,2,0 1444239166.56,4,2,1675,11111,0,238,49.8984375,2,0 1444239170.36,4,2,1675,10000,1,None,None,None,None 1444239176.58,4,2,1675,11111,1,237,49.8515625,0,4 1444239186.48,4,2,1675,11111,1,239,49.8984375,-3,7 1444239196.53,4,2,1675,11111,1,239,49.8515625,-4,8 1444239206.45,4,2,1675,11111,1,240,49.8984375,-4,7 1444239216.43,4,2,1675,11111,1,239,49.8984375,-4,8 1444239226.43,4,2,1675,11111,1,240,49.8984375,-4,7 1444239236.41,4,2,1675,11111,0,241,49.8984375,0,3 1444239246.39,4,2,1675,11111,0,239,49.8984375,2,0 1444239256.38,4,2,1675,11111,0,238,49.8984375,2,0 1444239266.38,4,2,1675,11111,0,238,49.94921875,2,0 1444239276.37,4,2,1675,11111,0,239,49.8984375,2,0 1444239286.35,4,2,1675,11111,0,239,49.94921875,2,0 1444239296.34,4,2,1675,11111,1,239,49.8984375,-2,4 1444239306.36,4,2,1675,11111,1,239,49.94921875,-4,8 1444239316.39,4,2,1675,11111,1,240,49.94921875,-4,8 1444239326.29,4,2,1675,11111,1,240,49.8984375,-3,7 1444239336.29,4,2,1675,11111,1,239,49.94921875,-4,8 1444239346.34,4,2,1675,11111,1,239,49.8984375,-4,7 1444239356.28,4,2,1675,11111,0,239,49.94921875,0,3 1444239366.22,4,2,1675,11111,0,240,49.8984375,2,0 1444239376.22,4,2,1675,11111,0,240,49.8984375,2,0 1444239386.22,4,2,1675,11111,0,240,49.8984375,0,0 1444239396.2,4,2,1675,11111,0,240,49.8515625,2,0 1444239406.18,4,2,1675,11111,0,240,49.8984375,2,0 1444239426.16,4,2,1675,11111,1,240,49.8984375,-3,7 1444239436.15,4,2,1675,11111,1,240,49.8515625,-5,8 1444239446.14,4,2,1675,11111,1,241,49.8984375,-4,8 1444239456.12,4,2,1675,11111,1,239,49.8515625,-4,8 1444239466.11,4,2,1675,11111,1,238,49.8515625,-4,8 1444239476.08,4,2,1675,11111,0,240,49.8515625,0,4 1444239486.08,4,2,1675,11111,0,240,49.8515625,2,0 1444239496.06,4,2,1675,11111,0,240,49.80078125,2,0 1444239506.05,4,2,1675,11111,0,240,49.8515625,2,0 1444239516.03,4,2,1675,11111,0,241,49.80078125,2,0 1444239526.02,4,2,1675,11111,0,241,49.80078125,0,0 1444239530.34,4,2,1675,10000,1,None,None,None,None 1444239536.0,4,2,1675,11111,1,241,49.8515625,0,4 1444239546.01,4,2,1675,11111,1,241,49.80078125,-3,7 1444239555.97,4,2,1675,11111,1,241,49.80078125,-4,7 1444239565.97,4,2,1675,11111,1,241,49.80078125,-3,7 1444239575.95,4,2,1675,11111,1,241,49.80078125,-4,8 1444239585.94,4,2,1675,11111,1,241,49.8515625,-4,8 1444239590.35,4,2,1675,10000,0,None,None,None,None 1444239595.91,4,2,1675,11111,0,241,49.8515625,0,3 1444239605.91,4,2,1675,11111,0,241,49.80078125,2,0 1444239615.91,4,2,1675,11111,0,240,49.80078125,2,0
Add file logging so that any messages coming from the MiHome adaptor get stored in a CSV file. This CSV file could then be used for post-analysis of data, or it could even be used with 'tail -f' to generate a feed of data into some other program.