This shows you the differences between two versions of the page.
| en:iot:examples:setup:confmode [2021/03/04 22:28] – created heiko.pikner | en:iot:examples:setup:confmode [Unknown date] (current) – external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Configuration mode example ====== | ||
| + | The code allows entering configuration mode when the button is pressed. | ||
| + | |||
| + | < | ||
| + | |||
| + | <code c> | ||
| + | /* | ||
| + | * IoT Configuration mode example | ||
| + | * | ||
| + | * IoT Button module is needed. When button is prsessed then module goes to | ||
| + | * the config mode | ||
| + | * | ||
| + | * Created 04 March 2021 by Heiko Pikner | ||
| + | */ | ||
| + | // Includes global variables and librarys that the RGB LED and buzzer uses | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | // Switch state to trigger restart only once. | ||
| + | int swState; | ||
| + | |||
| + | // Message received | ||
| + | void iot_received(String topic, String msg){} | ||
| + | |||
| + | // Function started after the connection to the server is established. | ||
| + | void iot_connected() | ||
| + | { | ||
| + | // Send message to serial port to show that connection is established. | ||
| + | Serial.println(" | ||
| + | |||
| + | // Send message to MQTT server to show that connection is established. | ||
| + | iot.log(" | ||
| + | } | ||
| + | |||
| + | void setup() | ||
| + | { | ||
| + | // Initialize serial port and send message | ||
| + | // setting up serial connection parameter | ||
| + | Serial.begin(115200); | ||
| + | Serial.println(" | ||
| + | |||
| + | // print IoT json config to serial | ||
| + | iot.printConfig(); | ||
| + | // Initialize IoT Button module switch pin D3 (0) as a boot pin.The pin was read, when module boots up. | ||
| + | iot.setBootPin(0); | ||
| + | // Initialize IoT library | ||
| + | iot.setup(); | ||
| + | } | ||
| + | |||
| + | void loop() | ||
| + | { | ||
| + | // IoT behind the plan work, it should be periodically called. | ||
| + | iot.handle(); | ||
| + | delay(20); | ||
| + | |||
| + | // Read the switch pin to force restart the module if it is in normal or config mode. | ||
| + | if(!digitalRead(0) && !swState) | ||
| + | { | ||
| + | iot.restart(ITT:: | ||
| + | swState = 1; | ||
| + | } | ||
| + | } | ||
| + | </ | ||