{"action":"created","issue":{"url":"https://api.github.com/repos/SignalK/specification/issues/291","repository_url":"https://api.github.com/repos/SignalK/specification","labels_url":"https://api.github.com/repos/SignalK/specification/issues/291/labels{/name}","comments_url":"https://api.github.com/repos/SignalK/specification/issues/291/comments","events_url":"https://api.github.com/repos/SignalK/specification/issues/291/events","html_url":"https://github.com/SignalK/specification/issues/291","id":188204053,"number":291,"title":"MQTT sensor connection example implementation","user":{"login":"toqduj","id":5449929,"avatar_url":"https://avatars.githubusercontent.com/u/5449929?v=3","gravatar_id":"","url":"https://api.github.com/users/toqduj","html_url":"https://github.com/toqduj","followers_url":"https://api.github.com/users/toqduj/followers","following_url":"https://api.github.com/users/toqduj/following{/other_user}","gists_url":"https://api.github.com/users/toqduj/gists{/gist_id}","starred_url":"https://api.github.com/users/toqduj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/toqduj/subscriptions","organizations_url":"https://api.github.com/users/toqduj/orgs","repos_url":"https://api.github.com/users/toqduj/repos","events_url":"https://api.github.com/users/toqduj/events{/privacy}","received_events_url":"https://api.github.com/users/toqduj/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":31,"created_at":"2016-11-09T09:46:03Z","updated_at":"2016-11-12T12:50:02Z","closed_at":null,"body":"Based on a request by @tkurki (requested in [this comment](https://github.com/SignalK/specification/issues/288#issuecomment-259089191) in #288 ), here's one possible implementation for letting sensors send information over Wifi & MQTT to the SK receiver.\r\n\r\nA short summary: I've created a straightforward GPS sensor (for deck mounting) by connecting an [Adafruit Ultimate GPS](https://www.adafruit.com/product/746) (based on the MTK3339 chip) to an [Arduino MKR1000](https://www.arduino.cc/en/Main/ArduinoMKR1000) and a LiPo back-up battery. The code for running the sensor is available [here](https://bitbucket.org/toQDuj/signalk-gps-nodule). It is not advanced code, but it is simple and works. \r\n\r\nThe code uses the following key libraries alongside standard ones:\r\n\r\n- [PubSubClient](http://pubsubclient.knolleary.net/api.html#connect1) for MQTT, modified to handle larger messages\r\n- [ArduinoJson](https://github.com/bblanchon/ArduinoJson) for constructing the SK deltas\r\n- [PString](http://arduiniana.org/libraries/pstring/) for handling the JSON string before sending. \r\n- [TinyGPS++](http://arduiniana.org/libraries/tinygpsplus/) for interpreting the GPS messages\r\n\r\nThe sensor module \"sender\" connects to a \"receiver\", a Raspberry Pi running OpenPlotter V0.9 (OP) in the following steps:\r\n\r\n1. The sensor connects to the OP-instantiated Wifi access point, currently using hardcoded information (SSID, WPA password). \r\n2. The sensor connects to the OP-instantiated Mosquitto MQTT server, currently using hardcoded information (IP, port, MQTT username, MQTT password). Once I find a compatible mDNS discovery library, the IP and port can be autofound.\r\n3. The sensor subscribes to an MQTT channel, \"gpsget\", set up for this purpose. \r\n4. The sensor outputs SK deltas to this channel, updating one variable per message (five messages in total for five navigation keys: position.latitude, position.longitude, position.altitude, speedOverGround, and courseOverGroundTrue). Due to the design of ArduinoJson, I could not get it to put multiple key:value combinations in a single message. Each message is about 160 bytes long, and contains the following information (which adheres to the SK delta format as far as I could understand):\r\n\r\n`{\r\n\t\"updates\": [{\r\n\t\t\"source\": {\r\n\t\t\t\"timestamp\": \"2016-11-09T09:15:36Z\",\r\n\t\t\t\"$source\": \"deck.gps001\"\r\n\t\t},\r\n\t\t\"values\": [{\r\n\t\t\t\"path\": \"navigation.speedOverGround\",\r\n\t\t\t\"value\": 0.8385444\r\n\t\t}]\r\n\t}]\r\n}`\r\n\r\nThe timestamp is the time which the GPS returns, i.e. the time when the reported values were valid, and so lags a little behind real time. \r\n\r\nCurrently, OpenPlotter does not parse incoming SK deltas yet, as explained by @sailoog [in this comment](https://github.com/sailoog/openplotter/issues/113#issuecomment-253212354). For now, I am waiting for that to be implemented, as MQTT appears to be a nice way of sending information. \r\n\r\nThere is a power-saving feature: if the GPS does not have a valid fix, the Wifi disconnects. Every time before sending a message, it is checked if Wifi and MQTT are connected (otherwise it reconnects). As such, it uses on average about 50-60 mA at 5V (0.3W). This can be reduced in the future by exploiting the built-in RTC as a watchdog timer. "},"comment":{"url":"https://api.github.com/repos/SignalK/specification/issues/comments/260120334","html_url":"https://github.com/SignalK/specification/issues/291#issuecomment-260120334","issue_url":"https://api.github.com/repos/SignalK/specification/issues/291","id":260120334,"user":{"login":"tkurki","id":1049678,"avatar_url":"https://avatars.githubusercontent.com/u/1049678?v=3","gravatar_id":"","url":"https://api.github.com/users/tkurki","html_url":"https://github.com/tkurki","followers_url":"https://api.github.com/users/tkurki/followers","following_url":"https://api.github.com/users/tkurki/following{/other_user}","gists_url":"https://api.github.com/users/tkurki/gists{/gist_id}","starred_url":"https://api.github.com/users/tkurki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tkurki/subscriptions","organizations_url":"https://api.github.com/users/tkurki/orgs","repos_url":"https://api.github.com/users/tkurki/repos","events_url":"https://api.github.com/users/tkurki/events{/privacy}","received_events_url":"https://api.github.com/users/tkurki/received_events","type":"User","site_admin":false},"created_at":"2016-11-12T12:50:02Z","updated_at":"2016-11-12T12:50:02Z","body":"Did you read the spec and the defaults for mqttjs? \r\n\r\nEvery MQTT client already MUST have a unique client id per MQTT spec. This is distinct from authentication credentials, which btw are part of the MQTT spec as well.\r\n\r\nHaving a persistent client id is however a problem - if no clientid is specified mqttjs creates a random clientid for every connection.\r\n\r\nBut this is just something that should be specified in the MQTT-to-SK gateway spec, like _\"a MQTT to Signal K gateway client MUST provide a persistent client identification . The identification SHOULD follow the format <some format that makes sense in the SK data model for multiple values>\"_. So persistence is a MUST in addition to what MQTT spec already specifies.\r\n\r\nWhere did the zero config requirement come from? There is yet no way for the MQTT client to discover the server, is there?"}}
{"actor":{"display_login":"tkurki"}}