Commit 79dc1fc3 authored by PhiBo's avatar PhiBo 🚀

Support mode switch

parent d10bb93f
...@@ -9,6 +9,11 @@ ...@@ -9,6 +9,11 @@
#define RPC_NUM_HANDLERS 20 #define RPC_NUM_HANDLERS 20
#define RPC_NUM_FUNCTIONS 0 #define RPC_NUM_FUNCTIONS 0
#define PIN_NODE_MODE 4
#define NODE_MODE_ACTIVE 0
#define NODE_MODE_CONFIG 1
#define PIN_ESP8266_SET 2 #define PIN_ESP8266_SET 2
#define PIN_ESP8266_MODE 3 #define PIN_ESP8266_MODE 3
#define PIN_ESP8266_CH_PD 7 #define PIN_ESP8266_CH_PD 7
...@@ -26,19 +31,31 @@ SensorWifiModuleRemote sensor_remote = SensorWifiModuleRemote(rpc_request, 0x00) ...@@ -26,19 +31,31 @@ SensorWifiModuleRemote sensor_remote = SensorWifiModuleRemote(rpc_request, 0x00)
SensorNode sensor_node = SensorNode(); SensorNode sensor_node = SensorNode();
uint8_t sensor_node_mode = NODE_MODE_ACTIVE;
void setup() { void setup() {
pinMode(PIN_NODE_MODE, INPUT);
pinMode(PIN_ESP8266_SET, OUTPUT); pinMode(PIN_ESP8266_SET, OUTPUT);
pinMode(PIN_ESP8266_MODE, OUTPUT); pinMode(PIN_ESP8266_MODE, OUTPUT);
pinMode(PIN_ESP8266_CH_PD, OUTPUT); pinMode(PIN_ESP8266_CH_PD, OUTPUT);
digitalWrite(PIN_ESP8266_CH_PD, LOW); digitalWrite(PIN_ESP8266_CH_PD, LOW);
RPC_SERIAL_PORT.begin(RPC_SERIAL_BAUD); RPC_SERIAL_PORT.begin(RPC_SERIAL_BAUD);
if(digitalRead(PIN_NODE_MODE) == HIGH) {
sensor_node_mode = NODE_MODE_CONFIG;
}
if(sensor_node_mode == NODE_MODE_ACTIVE) {
sensor_node.loadConfig();
} else {
}
/*sensor_dht = new DHT(6, DHT22); /*sensor_dht = new DHT(6, DHT22);
sensor_dht->begin();*/ sensor_dht->begin();*/
//mySerial.begin(9600); //mySerial.begin(9600);
//rpc.connectHandler(&sensor_node, 0x10); //rpc.connectHandler(&sensor_node, 0x10);
// put your setup code here, to run once: // put your setup code here, to run once:
sensor_node.loadConfig();
Serial.println("foo"); Serial.println("foo");
} }
...@@ -46,18 +63,21 @@ void loop() { ...@@ -46,18 +63,21 @@ void loop() {
//a->writeValue(); //a->writeValue();
//rpc_serial.readData(); //rpc_serial.readData();
//sensor_dht->readTemperature(); //sensor_dht->readTemperature();
sensor_node.run(); if(sensor_node_mode == NODE_MODE_ACTIVE) {
digitalWrite(PIN_ESP8266_SET, HIGH); sensor_node.run();
digitalWrite(PIN_ESP8266_MODE, HIGH); digitalWrite(PIN_ESP8266_SET, HIGH);
digitalWrite(PIN_ESP8266_MODE, HIGH);
digitalWrite(PIN_ESP8266_CH_PD, HIGH);
// Wait for bootloader digitalWrite(PIN_ESP8266_CH_PD, HIGH);
delay(250); // Wait for bootloader
digitalWrite(PIN_ESP8266_MODE, LOW); delay(250);
digitalWrite(PIN_ESP8266_SET, LOW); digitalWrite(PIN_ESP8266_MODE, LOW);
// Wait until boot digitalWrite(PIN_ESP8266_SET, LOW);
delay(250); // Wait until boot
sensor_node.submitValues(&sensor_remote); delay(250);
digitalWrite(PIN_ESP8266_CH_PD, LOW); sensor_node.submitValues(&sensor_remote);
delay(5000); digitalWrite(PIN_ESP8266_CH_PD, LOW);
delay(5000);
} else {
}
} }
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