Open usmantahirr opened 7 years ago
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. :
electron IPC Code:
ipc.on('device', (event, arg) => {
console.log("ipc called");
const DeviceServer = new DeviceHttpServer(arg);
DeviceServer.start();
});
Dynamic Server Code:
import http from "http";
class DeviceHttpServer{
constructor(device){
this.device = device;
console.log("DeviceHttpServer object created");
}
start(){
require( __dirname +"/" + this.device);
}
}
export default DeviceHttpServer;
cylon module code called by require:
import Cylon from "cylon";
Cylon.api("http", {
host: '127.0.0.1',
port: '3001',
ssl: false,
auth: false
});
Cylon.robot({
name: "hoge",
connections: {
bebop: { adaptor: 'hoge' }
},
devices: {
drone: { driver : 'hoge' }
},
work: function(my){
}
}).start();
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.