The VirginSoil-Full example comes with the IOTAppStory library as explained here.

This example code is the opposite of the previous example and uses all the options that come with the library. After compiling you will be able to:

  • press a button to check for updates or boot to configuration mode
  • let users change variable values in the "App Settings" page in config mode
  • give users feedback about the state of the app using callbacks
  • set the update interval to check for updates every x min / hour / days


Methods used

As we already talked about the defines, include & initializing the library in the previous example we will skip that here and go straight to the example vars on line 37 of the code.

// ======================== EXAMPLE VARS ======================== 
// used in this example to print variables every 10 seconds
unsigned long printEntry;

char* lbl         = "Light Show";
char* exampleURL  = "";
char* nrOf        = "6";

char* doSomething = "1";
char* chosen      = "0";

char* updInt      = "60";
char* ledPin      = "2";
char* timeZone    = "0.0";

With the exception of printEntry all the variables shown above are added to the "App Settings" page in config mode further down in the setup() code. Currently only char arrays are supported. Use functions like atoi() and atof() to transform the char array to integers or floats. And use dPinConv() to convert Dpin numbers to integers (D6 > 14)


// ======================== SETUP ======================== 
void setup() {
  /* TIP! delete lines below when not used */
  IAS.preSetDeviceName("virginsoil");                       // preset deviceName this is also your MDNS responder: http://virginsoil.local
  //IAS.preSetAutoUpdate(false);                            // automaticUpdate (true, false)
  //IAS.preSetAutoConfig(false);                            // automaticConfig (true, false)
  //IAS.preSetWifi("ssid","password");                      // preset Wifi
  /* TIP! Delete Wifi cred. when you publish your App. */

Find out more about presets here.


  IAS.addField(lbl, "textLine", 16);                        // These fields are added to the "App Settings" page in config mode and saved to eeprom. Updated values are returned to the original variable.
  IAS.addField(exampleURL, "Textarea", 80, \'T\');            // reference to org variable | field label value | max char return | Optional "special field" char
  IAS.addField(nrOf, "Number", 8, \'N\');                     // Find out more about the optional "special fields" at /wiki
  IAS.addField(doSomething, "Checkbox:Check me", 1, \'C\');
  IAS.addField(chosen, "Selectbox:Red,Green,Blue", 1, \'S\');

  IAS.addField(updInt, "Interval", 8, \'I\');
  IAS.addField(ledPin, "ledPin", 2, \'P\');
  IAS.addField(timeZone, "Timezone", 4, \'Z\');

This is where the previously declared variables are added as editable fields to the "App Settings" page in config mode.


  IAS.onModeButtonShortPress([]() {
    Serial.println(F(" If mode button is released, I will enter in firmware update mode."));

  IAS.onModeButtonLongPress([]() {
    Serial.println(F(" If mode button is released, I will enter in configuration mode."));

  IAS.onModeButtonVeryLongPress([]() {
    Serial.println(F(" If mode button is released, I won\'t do anything unless you program me to."));
    /* TIP! You can use this callback to put your app on it\'s own configuration mode */

You can configure callback functions that can give feedback to the app user about the current state of the application. In this example we use serial print to demonstrate the call backs. But you could use leds etc. These are only 3 of the available callbacks, find out more about callbacks here.




  //-------- Your Setup starts from here ---------------


The begin method has 1 optional parameter and is explained here.
setCallHome Set to true to enable calling home frequently (disabled by default)
setCallHomeInterval Call home interval in seconds, use 60s only for development. Please change it to at least 2 hours in production.

If posible place your personal code at the end of your setup. This gives the library a better chance in having enough memory to setup HTTPS connections for OTA updates on boot. In some rare occasions you might run into compatibillity issue with other libraries forcing you to place it at the beginning of the setup. This is ok, just don't make it a habbit.


// ======================== LOOP ========================
void loop() {

  //-------- Your Sketch starts from here ---------------


As mentioned before in the basic example the loop method handles the reaction of the MODEBUTTON and call home interval when set.

Just like with the setup() please place your code below the loop.

Added by