mongoose-os-rpc: a Node.js implementation of Mongoose OS' RPC protocol
mongoose-os-rpc is a client library that allows you to call remote functions (RPC) on devices which are running Mongoose OS (generally ESP8266). The library laverages Node's callbacks. Unconfirmed RPC calls will timeout and the caller will be notified about the failure.
Note: For instructions how to install and setup Mongoose OS, please visit the official site - https://mongoose-os.com/docs/quickstart/setup.html
Protocol support
This library implements the RPC protocol (JSON based) as described here: https://github.com/mongoose-os-libs/rpc-common
Transports
RPC packets are sent via a particular transport. Currently http, ws and mqtt are supported.
HTTP
The url format is: http://devideIpOrName/rpc
WS (WebSocket)
The url format is: ws://devideIpOrName/rpc
MQTT
The url format is: mqtt://devideIpOrName/deviceName
This transport requires a client id. If the clientId option was not specified a unique value will be generated. The RPC client will then subscribe to client-id/rpc topic, listening for replies.
Installing
npm install --save mongoose-os-rpc
Usage examples
Using Rpc class (automatic transport creation)
const Rpc = Rpc; // Instantiate Rpc object using the short format (specifying address property)// The Rpc object will internally create an instance of an appropriate transportlet rpc = address: 'http://deviceIpOrName/rpc' // OR: address: 'ws://deviceIpOrName/rpc' // OR: address: 'mqtt://deviceIpOrName/esp8266_C6D764' <-- In this case esp8266_C6D764 is device's name as configured in Mongoose OS
Manually creating a transport
const Rpc = Rpc;const HttpTransport = HttpTransport; let transport = address: 'http://deviceIpOrName/rpc'; let rpc = transport: transport
Calling FS.List function via http
const Rpc = Rpc; // Instantiate Rpc object using the short format (specifying address property)// The Rpc object will internally create an instance of an appropriate transportlet rpc = address: 'http://deviceIpOrName/rpc' // OR: address: 'ws://deviceIpOrName/rpc' // OR: address: 'mqtt://deviceIpOrName/esp8266_C6D764' <-- In this case esp8266_C6D764 is device's name as configured in Mongoose OS; // Subscribe for error eventsrpc // Subscribe for disconnect eventsrpc; // Subscribe for connect events// To distinguish between connect and reconnect use isReconnect() functionrpc;
TODO
- Implement and test transport authentication
- Implement tests