I am gathering network traffic from a small number of very chatty air con devices using Python. I see two types of message - one contains only the IP address and device name, and the other contains the IP address and the values I want to record - fan speed, temperature etc.
The devices generate messages far too fast (every 2-3 seconds) to be useful, and I don't want to generate hundreds of pointless database inserts. My idea is to parse the message, and if I have not seen the device before, create a data structure with the IP and Name.. if I have seen it before, I would like to update the data structure with the missing values. Once every minute or so, I would like to iterate the data structure to update a database with the current values.
I thought an array of objects might be the right way to go, but can't find simple examples; for each instance of a device, a dictionary looks like a sensible structure, but should I group these in an array?
Apologies if this is simplistic - I have not coded in many years, and have enjoyed figuring out how to capture network traffic and parse it using regular expression matching... but the huge range of data structures in python is overwhelming! What is a simple data structure that would let me easily query "does this device exist", and either create a new one, or update the existing one?