Commit 342d96e8 authored by PhiBo's avatar PhiBo 🚀

Initialize rpc handler

parent d7ab7e85
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#define RPC_SERIAL_PORT Serial #define RPC_SERIAL_PORT Serial
#define RPC_SERIAL_BAUD 9600 #define RPC_SERIAL_BAUD 9600
#define RPC_NUM_HANDLERS 20 #define RPC_NUM_HANDLERS 2
#define RPC_NUM_FUNCTIONS 0 #define RPC_NUM_FUNCTIONS 0
#define PIN_NODE_MODE 4 #define PIN_NODE_MODE 4
...@@ -20,10 +20,10 @@ ...@@ -20,10 +20,10 @@
SoftwareSerial mySerial(10, 11); SoftwareSerial mySerial(10, 11);
//ArduRPC rpc = ArduRPC(RPC_NUM_HANDLERS, RPC_NUM_FUNCTIONS); ArduRPC *rpc;
//ArduRPC_Serial rpc_serial = ArduRPC_Serial(RPC_SERIAL_PORT, rpc); ArduRPC_Serial *rpc_serial;
//ArduRPC_SensorNode sensor_node = ArduRPC_SensorNode(); ArduRPC_SensorNode *rpc_sensor_node;
ArduRPCRequest *rpc_request; ArduRPCRequest *rpc_request;
ArduRPCRequest_Serial *h; ArduRPCRequest_Serial *h;
...@@ -54,6 +54,10 @@ void setup() { ...@@ -54,6 +54,10 @@ void setup() {
sensor_node = new SensorNode(); sensor_node = new SensorNode();
sensor_node->loadConfig(); sensor_node->loadConfig();
} else { } else {
rpc = new ArduRPC(RPC_NUM_HANDLERS, RPC_NUM_FUNCTIONS);
rpc_serial = new ArduRPC_Serial(RPC_SERIAL_PORT, *rpc);
rpc_sensor_node = new ArduRPC_SensorNode(*rpc, "");
} }
/*sensor_dht = new DHT(6, DHT22); /*sensor_dht = new DHT(6, DHT22);
sensor_dht->begin();*/ sensor_dht->begin();*/
...@@ -83,5 +87,13 @@ void loop() { ...@@ -83,5 +87,13 @@ void loop() {
digitalWrite(PIN_ESP8266_CH_PD, LOW); digitalWrite(PIN_ESP8266_CH_PD, LOW);
delay(5000); delay(5000);
} else { } else {
digitalWrite(PIN_ESP8266_SET, HIGH);
digitalWrite(PIN_ESP8266_MODE, HIGH);
digitalWrite(PIN_ESP8266_CH_PD, HIGH);
// Wait for bootloader
delay(250);
digitalWrite(PIN_ESP8266_SET, LOW);
rpc_serial->loop();
} }
} }
...@@ -40,6 +40,7 @@ void SensorNode::loadConfig() ...@@ -40,6 +40,7 @@ void SensorNode::loadConfig()
sensor_type |= (uint8_t)EEPROM_read(pos); sensor_type |= (uint8_t)EEPROM_read(pos);
pos++; pos++;
if(sensor_type == 0) { if(sensor_type == 0) {
this->sensors[i] = NULL;
pos += 8; pos += 8;
continue; continue;
} }
...@@ -249,3 +250,17 @@ uint8_t SensorWifiModuleRemote::submitValue(uint8_t *data, uint8_t length) ...@@ -249,3 +250,17 @@ uint8_t SensorWifiModuleRemote::submitValue(uint8_t *data, uint8_t length)
return 0; return 0;
} }
ArduRPC_SensorNode::ArduRPC_SensorNode(ArduRPC &rpc, char *name) : ArduRPCHandler()
{
this->type = 0x9999;
this->registerSelf(rpc, name, (void *)this);
}
uint8_t ArduRPC_SensorNode::call(uint8_t cmd_id)
{
if (cmd_id == 0x10) {
return RPC_RETURN_SUCCESS;
}
return RPC_RETURN_COMMAND_NOT_FOUND;
}
...@@ -84,4 +84,12 @@ class SensorDHT : public BaseSensor ...@@ -84,4 +84,12 @@ class SensorDHT : public BaseSensor
DHT *dht; DHT *dht;
}; };
class ArduRPC_SensorNode : public ArduRPCHandler
{
public:
ArduRPC_SensorNode(ArduRPC &rpc, char *name);
uint8_t
call(uint8_t);
};
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment