Raspberry Pi - Rainforest EMU-2 - Python - Read time from SCE smart meter
Question: I am now to programming in Python and this is my first project. Any help would
be appreciated.

I recently obtained a device from Rainforest that reads my electric meter. The
unit has a USB port accessible via USB. I managed to hook the device up to my
Raspberry Pi and extract a hex string from the serial port. Currently the
string is reading 0x18f0cb39. I need to take this number and convert it into
proper format and output it as time and date. The manual for device I am
programming is at
<http://www.rainforestautomation.com/sites/default/files/download/rfa-z106/raven_xml_api_r127.pdf>

I am quite confused when it comes to converting epoch to time and date. I put
#'s in front of lines having difficulties.

The code that I have written is:

    
    
    #!/usr/bin/env python
    import serial
    import time
    serial.port = serial.Serial("/dev/ttyUSB0", 115200, timeout=0.5)
    serial.port.write("<Command><Name>get_time</Name><Refresh>N</Refresh></Command>")
    response=serialport.readline(none)
    response=serialport.readline(none)
    response=serialport.readline(none)
    response=serialport.readline(none)
    response=serialport.readline(none)
    myString=response[13:23]
    #struct_time = int(raw_input(((myString >> 40) +1970, (ts >> 32 & 0xFF) +1, ts >> 24 & 0xFF, ts>> 16)))
    #thetime=time.strftime("%7-%m-%d-%H-%M-%s)
    print myString
    

Thanks in advance for the help

Scott


Answer: Looking at the documentation, I don't understand exactly how you are using the
slice 13:23 to get your time (in hex) out of the TimeCluster response, but the
gist of your question and your commented out code seems to be how do I convert
0x18f0cb39 to a local date and time?

    
    
    >>> import time
    >>> help(time)
    (output snipped, but this is so handy....)
    >>> t = 0x18f0cb39
    >>> time.ctime(t)
    'Tue Apr  5 15:37:29 1983'
    >>> time.localtime(t)
    time.struct_time(tm_year=1983, tm_mon=4, tm_mday=5, tm_hour=15, tm_min=37, tm_sec=29, tm_wday=1, tm_yday=95, tm_isdst=0)
    

Since you posted your question 6 days ago and today is the 11th, the date in
that answer seems to be off by exactly 30 years, so I must be doing something
wrong, but maybe this will take you a step in the right direction or prompt
someone else to write a better answer for you.

