You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using Cylon for my Smart Devices framework, I am using MQTT for this purpose. I've defined a driver for my AirConditionar let's say. I have an ESP8026 chip in each AC which may use the different driver, but let's stick to one for now and I am using MQTT for communication.
I've added MQTT device with a topic devices/events on which every device will send data. I am using this device inside ESP's custom driver.
Now I want to add more devices dynamically to this robot in my MQTT's onConnect event on broker side. How can I do that?
classDriverextendsCylon.Driver{constructor(opts,cb){super(opts);this.setupCommands(Commands);this.deviceId=opts.deviceId||null;this.topic=opts.topic;this.commands=Commands;this.protobuf={};this.state={};this.initDriver(cb);debug(this.deviceId);}start(callback){constevents=['state','measurement','alert','log','ack'];events.forEach(function(e){this.defineDriverEvent(e);}.bind(this));if(this.robot.devices.deviceAdapter){this.connection.robot.devices.deviceAdapter.on('message',function(data){// TODO modify event based on type of data receiveddebug('Got data inside driver throught adapter',data.toString());this.emit('state',data);}.bind(this));}callback()}halt(callback){callback()}/** * Send standby command to OrientUltron * This capability is used to set standby mode of a device. * @param {String} value true | false */standby(value){constaction=this.protobuf.message.lookup('standby').name;this.sendToDevice(action,value||false);}/** * Send refresh command to OrientUltron * This capability is used to request all latest state values from a device. */refresh(){constaction=this.protobuf.message.lookup('refresh').name;this.sendToDevice(action,true);}/** * This is the thermostat's setpoint value, when the thermostat mode is set to Auto. The value will be fixed on 24. */thermostatAutoSetpoint(){constaction=this.protobuf.message.lookup('thermostatAutoSetpoint').name;this.sendToDevice(action,24);}/** * This is the thermostat's setpoint value, when the thermostat mode is set to Cool. The default value will be 24. The values ranges from 16 to 32. * @param {Number} value 16-32 */thermostatCoolingSetpoint(value){constaction=this.protobuf.message.lookup('thermostatCoolingSetpoint').name;this.sendToDevice(action,value||24);}/** * This is the thermostat's setpoint value, when the thermostat mode is set to Dry. The default value will be 24. The values ranges from 16 to 32. * @param {Number} value 16-32 */thermostatDrySetpoint(value){constaction=this.protobuf.message.lookup('thermostatDrySetpoint').name;this.sendToDevice(action,value);}/** * This is the thermostat's fan mode (speed). e.g. "4 = high", "3 = mid", "2 = low", "1 = auto". The default value will be "auto". * @param {Number} value 4 | 3 | 2 | 1 */thermostatFanMode(value){constaction=this.protobuf.message.lookup('thermostatFanMode').name;this.sendToDevice(action,value);}/** * This is the thermostat's setpoint value, when the thermostat mode is set to Heat. * @param {Number} value */thermostatHeatingSetpoint(value){constaction=this.protobuf.message.lookup('thermostatHeatingSetpoint').name;this.sendToDevice(action,value);}/** * This is the thermostat's fan mode. e.g. "1 = auto", "2 = cool", "3 = dry", "4 = heat", "5 = fan" * @param {Number} value 1 | 2 | 3 | 4 | 5 */thermostatMode(value){constaction=this.protobuf.message.lookup('thermostatMode').name;this.sendToDevice(action,value);}/** * Controls Vertical air flow direction of a device. * Send air flow change command to OrientUltron */verticalAirFlowDirection(){constaction=this.protobuf.message.lookup('verticalAirFlowDirection').name;this.sendToDevice(action,true);}/** * Controls horizontal air flow direction of a device. * Send air flow change command to OrientUltron */horizontalAirFlowDirection(){constaction=this.protobuf.message.lookup('horizontalAirFlowDirection').name;this.sendToDevice(action,true);}setState(state){if(this.protobuf.message){this.state=this.protobuf.decode(state);debug(this.state);}else{debug('state not updated');}}initDriver(filePath,cb){if(!this.protobuf.message){constpath=filePath||'./';this.protobuf=newProtocolBuffer('format',path,'ACDriver','ACActions',()=>{debug('protobuf loaded');if(cb)cb(this);});}else{debug('protobuf already loaded');}}sendToDevice(key,value){this.state[key]=value;this.connection.publish(this.topic,this.protobuf.encode(this.state));}}module.exports=Driver;
The text was updated successfully, but these errors were encountered:
Hello, I'm doing a dynamic driver configuration from electron UI & IPC by using require.
I think you can re-implement this code using Socket.io or MQTT. But probably you need to setup a different HTTP / MQTT port from the cylon-api-mqtt / http module.
:
I am using Cylon for my Smart Devices framework, I am using MQTT for this purpose. I've defined a driver for my AirConditionar let's say. I have an ESP8026 chip in each AC which may use the different driver, but let's stick to one for now and I am using MQTT for communication.
I've added MQTT device with a topic devices/events on which every device will send data. I am using this device inside ESP's custom driver.
Now I want to add more devices dynamically to this robot in my MQTT's onConnect event on broker side. How can I do that?
This is the way I am defining my driver
and this is the way I've defined my driver.
The text was updated successfully, but these errors were encountered: