Quick Start Demo

 

Feature Demonstration by Example

Create Device Template

 

Data Streams

 

Web Dashboard

Add a switch widget to the Web Dashboard:

Add the remaining widgets to the Web Dashboard for each Virtual Pin:

NOTE: The Web Dashboard is for design only and it does not show the live data from the Blynk Cloud.   Go to the device page to see the live data.  

Add a Device

In order to add a device and see the live data from the cloud on the Web Dashboard, you need to find and click on the 'Search' panel toolbar (this was not intuitive to me and it took some time to discover).  

After you create a new device, the Web Dashboard is shown with any live data available from the Blynk Cloud.  

Click on the 'Device Info' tab to get the 'Auth Token'.  

After the IoT device is setup to push data, the data will appear in the Web Dashboard as shown below.  

In a similar fashon, you can create a Mobile Dashboard (app) on your phone using the Blynk mobile app.   But now that we have the three items required for Static Provisioning (BLYNK_TEMPLATE_ID, BLYNK_DEVICE_NAME, and Auth Token), we can write our IoT device code.  

 

Write Code for IoT Device - Feather HUZZAH ESP8266


/*
  Adafruit Feather HUZZAH ESP8266 & Blynk 2021
  
*/

const boolean bPrintV0V1V2V3ToSerial = false;

// In the Arduino IDE:
//  Set the board to "Generic ESP8266 Module"
//  Set the board port (look at Windows Devices & Printers to identify the device port).

#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG   // When enabled, provides more debug detail.  Slows hardware by 10x
//#define BLYNK_NO_BUILTIN   // Disable built-in analog & digital pin operations to save Flash/RAM
#define BLYNK_TEMPLATE_ID "TMPLtu5CaJaZ"
#define BLYNK_DEVICE_NAME "Feather HUZZAH ESP8266"

//#define BLYNK_FIRMWARE_VERSION        "0.1.0"

// Install the Arduino library for ESP8266  
// https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266WiFi
#include <ESP8266WiFi.h>

// Install the Blynk library for ESP8266
#include <BlynkSimpleEsp8266.h>

// Get Auth Token in the Blynk App via Project Settings (nut icon).
char auth[] = "get-Auth-Token-from-Blynk-device-page";

// Your WiFi credentials.  Set password to "" for open networks.
char ssid[] = "your-wifi-hotspot-name";
char pass[] = "your-wifi-password";

const byte pinBuiltInRedLED = 0;  // reverse wired, LOW turns LED on
const byte pinBuiltInBlueLED = 2; // reverse wired, LOW turns LED on

/////////////////////////////////////////////////////////////////////////
//  V0  - random float (simulated sensor reading) sent every 3 seconds

// Max Blynk virtual pin update is 10 values/second or 1 value per second.
const unsigned long TIMER_INTERVAL_V0_MS = 1000;
unsigned long timerLastV0 = 0;
byte stateV0 = LOW;

void timerV0() {
  if (timerLastV0 > millis())  timerLastV0 = millis();
  if ((millis() - timerLastV0) > TIMER_INTERVAL_V0_MS) {
    float f = fGetIntUnSignedRandFloat();
    Blynk.virtualWrite(V0,f);
    if (bPrintV0V1V2V3ToSerial == true) {
      Serial.print("V0 = ");
      Serial.println(f);
    }
    // toggle stateV0 to blink built in red LED
    if (stateV0 == HIGH) {
      stateV0 = LOW;  
    } else {
      stateV0 = HIGH; 
    }
    digitalWrite(pinBuiltInRedLED, stateV0);
    timerLastV0 = millis(); 
  } // timer

} // timerV0()

/////////////////////////////////////////////////////////////////////////
//  V1  - random integer 0 or 255 (simulated sensor reading) sent every 
//        5 seconds to Blynk

// Max Blynk virtual pin update is 10 values/second or 1 value per second.
const unsigned long TIMER_INTERVAL_V1_MS = 1000;
unsigned long timerLastV1 = 0;
byte stateV1 = LOW;

void timerV1() {
  if (timerLastV1 > millis())  timerLastV1 = millis();
  if ((millis() - timerLastV1) > TIMER_INTERVAL_V1_MS) {
    long value = lGetLgSignedLong();
    Blynk.virtualWrite(V1,value); 
    if (bPrintV0V1V2V3ToSerial == true) {
      Serial.print("V1 = ");
      Serial.println(value);
    }
    // toggle stateV1 to blink built in blue LED
    if (stateV1 == HIGH) {
      stateV1 = LOW;
    } else {
      stateV1 = HIGH;
    }
    digitalWrite(pinBuiltInBlueLED, stateV1);
    timerLastV1 = millis();
  } // timer
} // timerV1()


/////////////////////////////////////////////////////////////////////////
//  V2  - string values sent every 8 seconds to Blynk

// Max Blynk virtual pin update is 10 values/second or 1 value per second.
const unsigned long TIMER_INTERVAL_V2_MS = 1000;
unsigned long timerLastV2 = 0;

void timerV2() {
  if (timerLastV2 > millis())  timerLastV2 = millis();
  if ((millis() - timerLastV2) > TIMER_INTERVAL_V2_MS) {
    //  NOTE:  Cannot send character array with .virtualWrite().  Argument must be string. 
    //String sV2 = "012345678901234";
    String sV2 = sGetRandomChar(15);
    Blynk.virtualWrite(V2, sV2);
    if (bPrintV0V1V2V3ToSerial == true) {
      Serial.print("V2 = '"); Serial.print(sV2); Serial.println("'");
    }
    timerLastV2 = millis();
  } // timer
} // timerV2()


/////////////////////////////////////////////////////////////////////////
//  V3  - enumerable with integer value of 0 to 4 corresponding to 
//      empty, 1/4, 1/2, 3/4, full sent every 8 seconds to Blynk

// Max Blynk virtual pin update is 10 values/second or 1 value per second.
const unsigned long TIMER_INTERVAL_V3_MS = 1000;
unsigned long timerLastV3 = 0;
byte lastV3 = 0;

void timerV3() {
  if (timerLastV3 > millis())  timerLastV3 = millis();
  if ((millis() - timerLastV3) > TIMER_INTERVAL_V3_MS) {
    // Alternate sending integer values of 0,1,2,3, and 4
    // to simulate the level of a tank increasing and then
    // becoming empty. 
    if (lastV3 == 4) {
      lastV3 = 0;
    } else if (lastV3 == 0) {
      lastV3 = 1;
    } else if (lastV3 == 1) {
      lastV3 = 2;
    } else if (lastV3 == 2) {
      lastV3 = 3;
    } else {
      lastV3 = 4;
    }
    Blynk.virtualWrite(V3, lastV3);
    if (bPrintV0V1V2V3ToSerial == true) {
      Serial.print("V3 = "); Serial.println(lastV3);
    }
    timerLastV3 = millis();
  } // timer
} // timerV3()

/////////////////////////////////////////////////////////////////////////
//  V10 - data received from Blynk Cloud (pushed by Web or Mobile Dashboard)

BLYNK_WRITE(V10) {   
  // Called when virtual pin V10 (dashboard switch) is updated from the 
  // Web Dashboard or Mobile Dashboard (app).
  int value = param.asInt(); 
  Serial.print("V10 = ");
  Serial.println(value);
} // BLYNK_WRITE(V10)

/////////////////////////////////////////////////////////////////////////
//  V11 - data received from Blynk Cloud (pushed by Web or Mobile Dashboard)

BLYNK_WRITE(V11) {   
  // Called when virtual pin V10 (dashboard slider) is updated from the 
  // Web Dashboard or Mobile Dashboard (app).
  int value = param.asInt(); 
  Serial.print("V11 = ");
  Serial.println(value);
} // BLYNK_WRITE(V11)

/////////////////////////////////////////////////////////////////////////


void setup() {
  Serial.begin(115200);
  while (!Serial) {
    delay(1);
  }
  Serial.println("\nSerial ready");

  pinMode(pinBuiltInRedLED, OUTPUT);
  digitalWrite(pinBuiltInRedLED, HIGH);
  
  pinMode(pinBuiltInBlueLED, OUTPUT);
  digitalWrite(pinBuiltInBlueLED, HIGH);
  
  Blynk.begin(auth, ssid, pass);

  Serial.println("Setup complete");
} // setup()

void loop() {
  
  Blynk.run();
  timerV0();
  timerV1();
  timerV2();
  timerV3();
  
} // loop()


/////////////////////////////////////////////////////////////////////////


String sGetRandomChar(int length) {
  String sStr;
  for (int i=0; i<length; i=i+2) {
    sStr += char(random(97,123));
    sStr += char(random(65,91));
  }
  return sStr;
} // sGetRandomChar()


long lGetLgSignedLong() {
  // long:  -2,147,483,648 to 2,147,483,647
  long myLong = random(2147483647);
  int sign = random(10);
  if (sign <= 5) {
    myLong = myLong * (-1);
  }
  return myLong;
} // lGetLgSignedLong()


float fGetIntUnSignedRandFloat() {
  long myLong = random(1000000, 3276700);
  long divisor = 100;
  int expnt = random(2,6);
  switch (expnt) {
    case 2:
      divisor = 100;
      break;
    case 3:
      divisor = 1000;
      break;
    case 4:
      divisor = 10000;
      break;
    case 5:
      divisor = 100000;
    default:
      divisor = 100;
  }
  float f = (float)myLong / divisor;
  return f;
} // fGetIntUnSignedRandFloat()


void blinkLED(byte ledPIN){
  //  consumes 300 ms.
  for(int i = 5; i>0; i--){
    digitalWrite(ledPIN, LOW);
    delay(30);
    digitalWrite(ledPIN, HIGH);
    delay(30);
  }    
} //blinkLED()

 

Create a Mobile Dashboard (App) - WiFi Device - Feather HUZZAH ESP8266

The images below show how to create a Mobile Dashboard (mobile app) directly from an Android phone.  

   

   

   

   

   

 

Issues Discovered During July 2021 Review

  • Mobile Dashboard or iOS mobile app doesn't allow you to see the Blynk Cloud data after creating an app.   I reported this issue to Blynk on 22 July 2021.  
  • The exact rate limits for pushing data from an IoT device to the Blynk Cloud via .virtualWrite() is poorly documented.  

 

 


Do you need help developing or customizing a IoT product for your needs?   Send me an email requesting a free one hour phone / web share consultation.  

 

The information presented on this website is for the author's use only.   Use of this information by anyone other than the author is offered as guidelines and non-professional advice only.   No liability is assumed by the author or this web site.  

Projects

January 2023

Gateway + Nodes


January 2023

Pre-Designed Solutions