Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Raspberry Pi Electricity Monitor

Raspberry Pi Electricity Monitor

How and why I built a system for monitoring the electricity consumption of my home with a Raspberry Pi. Full details at http://unop.co.uk. Check out http://shutdownscanner.com (a service for automatically monitoring how many computers have been left on out of hours)

James Singleton

July 10, 2013
Tweet

More Decks by James Singleton

Other Decks in Programming

Transcript

  1. Raspberry Pi Electricity Monitor
    Reverse Engineering Serial Data Protocols
    James Singleton
    unop.co.uk

    View Slide

  2. Maplin

    £13

    Download data feature

    www.maplin.co.uk/wireless-electricity-monitor-611581

    View Slide

  3. Looks like this...

    Windows only (and not very good)

    PC power consumption negates benefit

    View Slide

  4. And this...

    View Slide

  5. And this...

    View Slide

  6. And this...

    View Slide

  7. And sometimes like this...

    View Slide

  8. That makes socket sad

    View Slide

  9. Linux

    Windows requires a driver install

    And it's buggy (causes BSOD)

    USB serial driver included on Raspbian

    Just plug it in

    And you can talk to the device

    View Slide

  10. That makes socket smile

    View Slide

  11. View Slide

  12. View Slide

  13. View Slide

  14. View Slide

  15. How

    That's the why and the results

    You can read about the rest of the results online

    But how would you go about making generic
    hardware work on another OS?

    Methods and tools

    RS232 hackery

    View Slide

  16. Sniff the data

    View Slide

  17. The data
    0 0.09933916sems.exeIRP_MJ_CREATE ProlificSerial0 SUCCESS Options: Open
    1 0.00001928sems.exeIOCTL_SERIAL_SET_QUEUE_SIZE ProlificSerial0 SUCCESS InSize: 2500 OutSize: 2500
    2 0.00000559sems.exeIOCTL_SERIAL_GET_BAUD_RATE ProlificSerial0 SUCCESS
    3 0.00000419sems.exeIOCTL_SERIAL_GET_LINE_CONTROL ProlificSerial0 SUCCESS
    4 0.00000391sems.exeIOCTL_SERIAL_GET_CHARS ProlificSerial0 SUCCESS
    5 0.00000391sems.exeIOCTL_SERIAL_GET_HANDFLOW ProlificSerial0 SUCCESS
    6 0.00000391sems.exeIOCTL_SERIAL_GET_BAUD_RATE ProlificSerial0 SUCCESS
    7 0.00000363sems.exeIOCTL_SERIAL_GET_LINE_CONTROL ProlificSerial0 SUCCESS
    8 0.00000363sems.exeIOCTL_SERIAL_GET_CHARS ProlificSerial0 SUCCESS
    9 0.00000363sems.exeIOCTL_SERIAL_GET_HANDFLOW ProlificSerial0 SUCCESS
    100.05133837sems.exeIOCTL_SERIAL_SET_BAUD_RATE ProlificSerial0 SUCCESS Rate: 9600
    110.00038217sems.exeIOCTL_SERIAL_SET_RTS ProlificSerial0 SUCCESS
    120.00098141sems.exeIOCTL_SERIAL_SET_DTR ProlificSerial0 SUCCESS
    130.00094090sems.exeIOCTL_SERIAL_SET_LINE_CONTROL ProlificSerial0 SUCCESS StopBits: 1 Parity: NONE WordLength: 8
    140.00003269sems.exeIOCTL_SERIAL_SET_CHAR ProlificSerial0 SUCCESS EOF:0 ERR:0 BRK:0 EVT:0 XON:11 XOFF:13
    150.00000503sems.exeIOCTL_SERIAL_SET_HANDFLOW ProlificSerial0 SUCCESS Shake:1 Replace:40 XonLimit:2048 XoffLimit:512
    160.00000810sems.exeIOCTL_SERIAL_PURGE ProlificSerial0 SUCCESS Purge: TXCLEAR RXCLEAR
    170.00000447sems.exeIOCTL_SERIAL_SET_TIMEOUTS ProlificSerial0 SUCCESS RI:20 RM:20 RC:20 WM:20 WC:3000
    180.00000503sems.exeIOCTL_SERIAL_GET_COMMSTATUS ProlificSerial0 SUCCESS
    190.00086547sems.exeIRP_MJ_WRITEProlificSerial0 SUCCESS Length 4: ....
    200.03268125sems.exeIRP_MJ_READ ProlificSerial0 TIMEOUT Length 8: ........
    211.30080499sems.exeIRP_MJ_READ ProlificSerial0 TIMEOUT Length 0:
    220.00082832sems.exeIRP_MJ_WRITEProlificSerial0 SUCCESS Length 4: ....
    231.30087539sems.exeIRP_MJ_READ ProlificSerial0 TIMEOUT Length 0:
    240.00047604sems.exeIRP_MJ_WRITEProlificSerial0 SUCCESS Length 4: ....
    250.07094952sems.exeIRP_MJ_READ ProlificSerial0 SUCCESS Length 64: S01....2S0222..1S03....2S04....2S05....2S06....2S07....2S08....2
    260.06694426sems.exeIRP_MJ_READ ProlificSerial0 SUCCESS Length 64: S09....2S10....2S11....2S12....2S13....2S14....2S15....2S16....2
    270.02160247sems.exeIRP_MJ_READ ProlificSerial0 TIMEOUT Length 1: .
    281.30083293sems.exeIRP_MJ_READ ProlificSerial0 TIMEOUT Length 0:
    290.00047799sems.exeIRP_MJ_WRITEProlificSerial0 SUCCESS Length 4: ....
    300.05098469sems.exeIRP_MJ_READ ProlificSerial0 SUCCESS Length 64: S01DAY..........................................................
    310.06696158sems.exeIRP_MJ_READ ProlificSerial0 SUCCESS Length 64: ......................MON.......................................
    320.03139673sems.exeIRP_MJ_READ ProlificSerial0 TIMEOUT Length 10: ..........
    331.30079717sems.exeIRP_MJ_READ ProlificSerial0 TIMEOUT Length 0:

    View Slide

  18. Hex
    190.00088894sems.exeIRP_MJ_WRITEProlificSerial0 SUCCESS Length 4: AA 00 00 AD
    200.03275919sems.exeIRP_MJ_READ ProlificSerial0 TIMEOUT Length 8: AA F0 00 AD 01 00 01 00
    211.30085695sems.exeIRP_MJ_READ ProlificSerial0 TIMEOUT Length 0:
    220.00095264sems.exeIRP_MJ_WRITEProlificSerial0 SUCCESS Length 4: AA 01 00 AD
    230.05059023sems.exeIRP_MJ_READ ProlificSerial0 SUCCESS Length 64: 53 30 31 44 41 59 07 00 08 00 08 00 08 00 0C 0
    240.06584636sems.exeIRP_MJ_READ ProlificSerial0 SUCCESS Length 64: 06 00 07 00 09 00 08 00 09 00 0C 00 0E 00 08 0
    250.03186327sems.exeIRP_MJ_READ ProlificSerial0 TIMEOUT Length 10: 00 00 00 00 00 00 00 00 00 11
    261.30084215sems.exeIRP_MJ_READ ProlificSerial0 TIMEOUT Length 0:
    270.00109204sems.exeIRP_MJ_WRITEProlificSerial0 SUCCESS Length 4: AA 02 00 AD
    280.06994297sems.exeIRP_MJ_READ ProlificSerial0 SUCCESS Length 64: 53 30 31 FF FF 00 00 32 53 30 32 32 32 13 08 3
    290.06694873sems.exeIRP_MJ_READ ProlificSerial0 SUCCESS Length 64: 53 30 39 FF FF 00 00 32 53 31 30 FF FF 00 00 3
    300.02180892sems.exeIRP_MJ_READ ProlificSerial0 TIMEOUT Length 1: F9
    311.30084885sems.exeIRP_MJ_READ ProlificSerial0 TIMEOUT Length 0:
    320.00063863sems.exeIRP_MJ_WRITEProlificSerial0 SUCCESS Length 4: AA 01 00 AD
    330.05113499sems.exeIRP_MJ_READ ProlificSerial0 SUCCESS Length 64: 53 30 31 44 41 59 07 00 08 00 08 00 08 00 0C 0
    340.06591955sems.exeIRP_MJ_READ ProlificSerial0 SUCCESS Length 64: 06 00 07 00 09 00 08 00 09 00 0C 00 0E 00 08 0
    350.03220409sems.exeIRP_MJ_READ ProlificSerial0 TIMEOUT Length 10: 00 00 00 00 00 00 00 00 00 11
    361.30084410sems.exeIRP_MJ_READ ProlificSerial0 TIMEOUT Length 0:
    370.00054309sems.exeIRP_MJ_WRITEProlificSerial0 SUCCESS Length 4: AA 02 00 AD
    380.07091544sems.exeIRP_MJ_READ ProlificSerial0 SUCCESS Length 64: 53 30 31 FF FF 00 00 32 53 30 32 32 32 D2 07 3
    390.06695292sems.exeIRP_MJ_READ ProlificSerial0 SUCCESS Length 64: 53 30 39 FF FF 00 00 32 53 31 30 FF FF 00 00 3
    400.02219137sems.exeIRP_MJ_READ ProlificSerial0 TIMEOUT Length 1: B7
    411.30084717sems.exeIRP_MJ_READ ProlificSerial0 TIMEOUT Length 0:

    View Slide

  19. Reimplement

    Poll

    Extract value

    Compress

    Save

    Host

    Graph

    Cron tail

    Digital sign (local or remote)

    View Slide

  20. Future improvements

    Use a DB (SQLite)

    Post to online API

    Combine with pricing data

    Calibrate against meter

    Combine with plug in meter for voltage

    An app!

    View Slide

  21. The plug

    I've got a startup

    Shutdown Scanner

    Service to automatically measure how much
    power/money is wasted by inactive computers
    left on over night or at weekends

    ShutdownScanner.com

    Lots more graphs

    View Slide

  22. View Slide

  23. View Slide

  24. View Slide

  25. Thanks

    View Slide