Differences

This shows you the differences between two versions of the page.

Link to this comparison view

en:iot:examples:setup:confmode [2021/03/04 22:28] – created heiko.pikneren: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>lib_deps = ITTIoT</code>
 +
 +<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 <Arduino.h>
 +#include <ittiot.h>
 +
 +// 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("MQTT connected callback");
 +
 +  // Send message to MQTT server to show that connection is established.
 +  iot.log("IoT Boot mode sample!");
 +}
 +
 +void setup()
 +{
 +  // Initialize serial port and send message
 +  // setting up serial connection parameter
 +  Serial.begin(115200);
 +  Serial.println("Booting");
 +
 +  // 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::configMode);
 +    swState = 1;
 +  }
 +}
 +</code>
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0