And the reasoning behind some of my decisions.....
My goal with this project is to have a whole suite of devices that expose their control in an easy to use way.
I took a bit of inspiration from can bus design, some devices just announce what’s happening to them, and you can chose to listen to it, or just ignore it. Then you have commands that are targeted from 1 device directly to another, and once again, we can listen to this, or ignore it because it isn’t meant for us.
We will be broadcasting when a device comes online and available on the control port broadcast, and we will also transmit a beacon on this port.
Anything to do with device announcements and configuration should happen on this port.
The control port should announce the current status of all aspects of the device when it comes online. It will announce all status changes for masters to listen to. It will also respond to group commands for the type of device it represents, and targeted commands sent to the device.
The thing I like most about this design is that we can also number every message coming from each device so that even though it’s UDP, if we have a master listening to all the traffic it can respond and request any missing info.
The rest of this post is mostly just me writing down my current thoughts on this API I am proposing.
UDP Broadcast port 24000: Management
Command Format:
{"EVENT":"ADD","SerialNumer":"0000ff112233","CurrentIdx":101,"productDescriptor":"IOSERVER","VARS":"INPUTS(8);OUTPUTS(8)"}
EVENT: ADD/REMOVE
SerialNumber: unique identifier for the device
CurrentIdx: the current index being used from the device
productDescriptor: anyone one of the defined descriptors available
IOSERVER,LIGHTSENSOR,TEMPSENSOR,HUMIDITYSENSOR,LIGHT,FANSPEED,SHADE,MOTION,SECURITY,LOCKCONTROLLER,THERMOSTAT
VARS: product specific variables, usually the count.
REMOVE *serial*
To signal a resource going offline:
{"EVENT":"REMOVE","SerialNumer":"0000ff112233"}
UDP Broadcast port 24001: Device data
An update from a device would look like the following:
{"EVENT":"UPDATE","SerialNumer":"0000ff112233","Index":305,"productDescriptor":"IOSERVER","VARS":"INPUTS(8)=[1,1,1,1,0,0,0,0];OUTPUTS(8)=[1,0,1,0,1,0,1,0]"}
Index: the current message index for that device, all messages are sequential
{"EVENT":"COMMAND","SerialNumer":"0000ff112233","Index":312,"productDescriptor":"IOSERVER","VARS":"OUTPUT()=[1,1,1,1,0,0,0,0]"}
{"EVENT":"COMMAND","SerialNumer":"0000ff112233","Index":355,"productDescriptor":"IOSERVER","VARS":"OUTPUT(2)=[1]"}
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.