Commit 158300d9 authored by PhiBo's avatar PhiBo 🚀

Add new rpc remote api

parent 7654b4dd
......@@ -15,6 +15,7 @@ uint8_t node_mode = 1;
ArduRPC *rpc;
ArduRPC_Serial *rpc_serial;
ArduRPC_SensorNode *rpc_sensor_node;
ArduRPC_SensorNodeRemote *sensor_remote;
ESP8266WebServer *server;
......@@ -23,6 +24,7 @@ void setup() {
pinMode(0, INPUT);
pinMode(2, INPUT);
uint8_t pin_mode;
ArduRPCRequest *rpc_request;
while(digitalRead(0) == HIGH) {
delay(50);
......@@ -49,6 +51,9 @@ void setup() {
rpc_sensor_node = new ArduRPC_SensorNode(*rpc, "wifi");
} else if (node_mode == NODE_MODE_CONFIG) {
server = new ESP8266WebServer(80);
rpc_request = new ArduRPCRequest();
new ArduRPCRequest_Serial(*rpc_request, RPC_SERIAL_PORT);
sensor_remote = new ArduRPC_SensorNodeRemote(*rpc_request, 0x00);
initConfig();
WiFi.mode(WIFI_AP_STA);
......@@ -67,6 +72,7 @@ void setup() {
server->on("/config/wifi/sta/password", handlePassword);
server->on("/info/wifi/ssids", handleScanSSID);
server->on("/info/wifi/sta", handleInfoWiFiSTA);
server->on("/setup", []() {
server->setContentLength(sizeof(PAGE_setup));
server->sendHeader("Content-Encoding", "gzip");
......
#include "sensor_node.h"
ArduRPC_SensorNodeRemote::ArduRPC_SensorNodeRemote(ArduRPCRequest &rpc, uint8_t handler_id) : ArduRPCRequestHandler()
{
this->_rpc = &rpc;
this->_handler_id = handler_id;
}
uint8_t ArduRPC_SensorNodeRemote::getMaxSensorCount()
{
uint8_t value;
this->_rpc->reset();
this->_rpc->call(this->_handler_id, 0x09);
value = this->_rpc->readResult_uint8();
return value;
}
......@@ -64,6 +64,15 @@ class ArduRPC_SensorNode : public ArduRPCHandler
char sensor_key[SENSOR_NODE_UUID_MAX_LENGTH + 1];
};
class ArduRPC_SensorNodeRemote : public ArduRPCRequestHandler
{
public:
ArduRPC_SensorNodeRemote(ArduRPCRequest &rpc, uint8_t handler_id);
uint8_t
getMaxSensorCount();
};
void ICACHE_FLASH_ATTR handleAPIHostname();
void ICACHE_FLASH_ATTR handleAPIPort();
void ICACHE_FLASH_ATTR handleInfoWiFiSTA();
......@@ -79,6 +88,7 @@ void ICACHE_FLASH_ATTR submitFile(PGM_VOID_P, uint16_t);
extern ESP8266WebServer *server;
extern WiFiClient *client;
extern ArduRPC_SensorNodeRemote *sensor_remote;
// EEPROM helper functions
uint8_t ICACHE_FLASH_ATTR readEEPROM_string(uint16_t, char *, uint8_t);
......
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