a module (brain or simple MCU) must provide the following info upon request. The server should be able to understand and implement something like:
WebSocketSend(JSON.stringify(["cmd", {
deviceID: "uuid-string",
cmd: "on"
}, {
deviceID: "other-uuid-string",
cmd: "0.5"
}]);-
arrayofobjectsrepresenting an individual peripheral, including how to interact with it, meta information like units or capabilities, etc. -
each
objectshould have a minimum set of keys:deviceID- a GUID string (v4), or some other identifying string.deviceType- a string of the enumerationbutton|slider|virtual.buttonmust handle onlyon|off|toggle. additional operations may be added, like toggle frequency, or others.slidersmay offer a direct setting,0.5, for 50%, or functions therein, likeincrement <value>|decrement <value>.virtualmust define the commands available, e.g.init,read,write,reset,calibrate,continuous-reading,modeX, etc.
deviceCmds- an array of valid commands.button&slidershould have base defaults, but may be described here. Virtual must have this field.meta- an object containing various meta information that device engine doesn't care about, but an end user might appreciate knowing. e.g. is the pressure reading from a sensor in Pascals (Pa), kiloPascals (kPa), bars, newtons, etc. An example of ametaobject:
"meta": { "buttonType": "Mains Relay", "limits": "10A/250AC 20A/120AC", "description": "Simple switch" }
Such an object might be used to determine potential saftey issues (e.g. a power meter says a line is using 15A/250AC, but the
limitsfield sets a safety limit so the app might turn it off). Or something like the following:"meta": { "outputs": [ { "metric": "Temperature", "unit": "C" }, { "metric": "Humidity", "unit": "%RH" } ], "validRange": [ -40, 85 ], "sensorModel": "DHT22", "Desctription": "Temperature & Humidity Sensor" }
-
Additional keys may be added.
Ultimately, who am I to tell you how to implement something. That said, at a minimum, the server must be able to identify a specific device and exchange data with it. To that end, a sequence of: the client module comes on-line, connects to the server over Web Sockets (or some other means like MQTT/AMQT, radio packets, wtf-ever), then delivers it's Resource list which should include everything needed to access them.
As for the local implementation, you will need to know about pins, busses (i2c, spi), specifics about your hardware (is your ADC 10bit, 12bit, 14bit, so that you can present meaningful data [0-3.3v is different than 0-4096 as an integer.])