Not knowing a better way to have one model for numerous sites, I implemented the following and would appreciate feedback if there’s a more elegant (aka better) design. At this time, the system I’ve built is only for internal use at numerous sites, but we’re always considering the possibility of commercializing it.
Here’s how it goes:
In the agent at startup, I extract the unique “tail” of the agent’s URL and issue a http GET to my server to get the configuration settings for both the agent and the device.
The PHP code on my server uses the tail that’s passed as the primary key to a table holding all of the required information, such as GroveStreams API key, type of device connected to each port, name of the data stream on each port, etc. This data is packaged up and sent back to the agent in JSON format.
There’s a http handler in agent to receive the message from the server, extract what it needs to post data to GroveStreams and then builds a table that it sends to the device in order for the device to get its configuration. This also allows me to “push” new settings to the agent and/or device if I change any of them in the database.
The device has a handler which extracts the configuration settings it receives from the agent.
When the device starts up, it notices it has no configuration, so it sends a message to the agent to get settings. I guess I could use NV storage, but haven’t implemented this aspect yet. I’m not sure there’s much benefit and what I’m doing ensures I always have the most recent configuration.
So far, this all seems to work swimmingly well. However, since I work in a vacuum (with the benefit of forums such as this), I need a sanity check…as does my code!
Thanks for any constructive feedback!