100 Days of Code – Day 2

After finding and fixing the dictionary problem last night, I’m feeling less defeated. This evening I finished the JSON parsing code. It’s not a lot to show for an hour’s work, but at least it’s progress.

{"Time":"2019-01-30T21:40:45.332439321-08:00","Offset":0,"Length":0,"Message":{"ID":12345678,"Type":7,"TamperPhy":2,"TamperEnc":0,"Consumption":1758381,"ChecksumVal":11007}}
{"Time":"2019-01-30T21:55:32.567053829-08:00","Offset":0,"Length":0,"Message":{"FrameSync":5795,"ProtocolID":30,"EndpointType":156,"EndpointID":98765432,"Consumption":209856,"Tamper":3080,"PacketCRC":62927}}

Looking at the sample rtlamr output above, we can see two distinct formats for meter reports. They both contain Consumption fields, but one has some extra protocol-related fields and uses different names for a few of the fields, the most notable being EndpointID instead of ID. In these cases I’m creating a new ID key and assigning it the value of the EndpointID key.

Next, I’m flattening the data structure so that there’s no longer a nested Message dictionary. Because I’m only concerned with the Time, ID, and Consumption keys, I’m copying the ID and Consumption keys to the outermost dictionary, and then deleting the Message key. I’m also deleting the Offset and Length keys since I don’t have a use for them (and they seem to always have a value of zero anyway). What I’m left with is a dictionary containing only the three keys I need. I then append the dictionary to a list.

I think my next step is to start reading up on the various Python visualization libraries, and deciding which one is a good fit for what I want to accomplish in this project.

Leave a Reply