IoT Octopus : send data using Blynk

by

Blynk is another way of sending and visualising data, from the Octopus, besides using Thingsspeak. To use Blynk, one needs to register with Blynk and download the Blynk app (available on iOS and Android).

Set up a remote sensing device on Blynk

To set up a data transmitting device on Blynk, one needs to do the following:

From the Blynk app :
– Open the Blynk app on your smartphone.
– Click on “new project”.
– Choose “esp8266” for the “choose device” question.
– Wait for the “Auth Token” email that Blynk has sent.

(then) In ArduBlocks :
– In the Setup part of your ArduBlocks sketch, add aWLAN block and a Blynk-Cloud block.
– In the WLAN block : specify the name of your wifi network and the password.
– In the Blynk-Cloud block : the Copy the Auth Token from the Blynk email, and paste it into the API-Key part of the ArduBlocks Blynk-Cloud block.

(more) in ArduBlocks :
– In the loop part of the ArduBocks sketch, add a Blynk-VirtualWrite block.
– In the Pin part of the block, specify by which Pin a sent value is referred to.
– In the “Value”/”Wert” part of the Blynk-VirtualWrite block, specify the variable to be sent to the Blynk app on your smartphone, as well as the Pin number that identifies this variable.
(if you’d like to send different variables, you can add more Blynk-VirtualWrite blocks, though with a different Pin for each block and variable one wants to send).

And another note regarding the ArduBlocks sketch. Save/set the sensor reading as a variable, rather than read it anew, creating slowdowns, every time it is used. For instance, rather than read the sensor value when it is printed to the serial and then again when it is written to the Blynk-VirtualWrite and sent with Blynk, save it as a variable, and you can simply use the variable in subsequent programming blocks needing the sensor value.

The “Set Number-Variable” block is in fact a very handy thing. This allows one to create a variable based on some value – eg. a sensor reading, or a calculated value. This way one could for instance have a variable loop Delay (ie Wait) time, depending on the sensor value.
One needs to set the variable before one uses it. Thus the “Set Number-Variable” block needs to be above the blocks where the variable is (later) used. 

Set up the Blynk app itself :

  • Go to “new project”
  • Long press on the black area.
  • This opens an area with a great many display options.
    (alas, some of the options require buying, to be used 😦 )
  • To be economical, I’ve selected to use a “Value display”. 
    • This is inserted on the top left. 
    • You can access the display’s options by tapping it. 
    • You can set a title, eg “IAQ”. 
    • For the “Input”, select the PIN of the ArduBlocks variable you would like to show.
    • Turn the average to “virtual” and set the pin to V1.
  • “Refresh interval”. Set this to “push”.
    • The two values next to the Pin is the value range of the display. Since the IAQ value can go up to 200, I’ve set the top value as 200.
      These values are perhaps not that important to set for a display that has a numeric readout, such as we’re using here. However, if one uses a line-/bar-chart or a circular chart, then it’s important to specify the expected value range, as this will set the visual scale of the displayed data.

To get things going, simply press the triangle on the top right of your mobile’s Blynk app window, and Blynk should receive and show incoming data values.

What a finished IAQ overview can look like in the Blynk app

Find the Blynk documentation here

The Arduino text code, for the Octopus part, looks like this:

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <bsec.h>
#include <Wire.h>
#include <Ticker.h>
String matrixausgabe_text  = " "; // Ausgabetext als globale Variable
volatile int matrixausgabe_index = 0;// aktuelle Position in Matrix
IPAddress myOwnIP; // ownIP for mDNS 
int IAQ = 0 ;
/* 
 Bosch BSEC Lib, https://github.com/BoschSensortec/BSEC-Arduino-library
 The BSEC software is only available for download or use after accepting the software license agreement.
 By using this library, you have agreed to the terms of the license agreement: 
 https://ae-bst.resource.bosch.com/media/_tech/media/bsec/2017-07-17_ClickThrough_License_Terms_Environmentalib_SW_CLEAN.pdf */
Bsec iaqSensor;     // Create an object of the class Bsec 
Ticker Bsec_Ticker; // schedule cyclic update via Ticker 
// ------------------------   Helper functions Bosch Bsec - Lib 
void checkIaqSensorStatus(void)
{ 
  String output; 
  if (iaqSensor.status != BSEC_OK) {
    if (iaqSensor.status < BSEC_OK) {
      output = "BSEC error code : " + String(iaqSensor.status);
      for (;;) {
        Serial.println(output);
        delay(500);
      } // Halt in case of failure 
    } 
    else {
      output = "BSEC warning code : " + String(iaqSensor.status);
      Serial.println(output);
    }
  }
  if (iaqSensor.bme680Status != BME680_OK) {
    if (iaqSensor.bme680Status < BME680_OK) {
      output = "BME680 error code : " + String(iaqSensor.bme680Status);
      for (;;){
        Serial.println(output);
        delay(500);
      }  // Halt in case of failure 
    } 
    else {
      output = "BME680 warning code : " + String(iaqSensor.bme680Status);
      Serial.println(output);
    }
  }
}
// Housekeeping: scheduled update using ticker-lib
void iaqSensor_Housekeeping(){  // get new data 
  iaqSensor.run();
}
void setup(){ // Einmalige Initialisierung
  Serial.begin(115200);
  Wire.begin(); // ---- Initialisiere den I2C-Bus 
  iaqSensor.begin(BME680_I2C_ADDR_PRIMARY, Wire);
  String output = "\nBSEC library version " + String(iaqSensor.version.major) + "." + String(iaqSensor.version.minor) + "." + String(iaqSensor.version.major_bugfix) + "." + String(iaqSensor.version.minor_bugfix);
  Serial.println(output);
  checkIaqSensorStatus();
  bsec_virtual_sensor_t sensorList[10] = {
    BSEC_OUTPUT_RAW_TEMPERATURE,
    BSEC_OUTPUT_RAW_PRESSURE,
    BSEC_OUTPUT_RAW_HUMIDITY,
    BSEC_OUTPUT_RAW_GAS,
    BSEC_OUTPUT_IAQ,
    BSEC_OUTPUT_STATIC_IAQ,
    BSEC_OUTPUT_CO2_EQUIVALENT,
    BSEC_OUTPUT_BREATH_VOC_EQUIVALENT,
    BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_TEMPERATURE,
    BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_HUMIDITY,
  };
  iaqSensor.updateSubscription(sensorList, 10, BSEC_SAMPLE_RATE_LP);
  checkIaqSensorStatus();  
  iaqSensor_Housekeeping();
  Bsec_Ticker.attach_ms(3000, iaqSensor_Housekeeping);
  Serial.println();
  //------------ WLAN initialisieren 
  WiFi.persistent(false);
  WiFi.mode(WIFI_STA);
  delay(100);
  Serial.print ("\nWLAN connect to:");
  Serial.print("BIG-RUCKUS");
  WiFi.begin("BIG-RUCKUS","prestige999%!");
  while (WiFi.status() != WL_CONNECTED) { // Warte bis Verbindung steht 
    delay(500); 
    Serial.print(".");
  };
  Serial.println ("\nconnected, meine IP:"+ WiFi.localIP().toString());
  matrixausgabe_text = " Meine IP:" + WiFi.localIP().toString();
  myOwnIP = WiFi.localIP();
  matrixausgabe_index=0;
  Blynk.config("SZ2mHs8Dk3poz6mbxC3BBeh4cgIH7DLb","blynk-cloud.com",80);// Downloads, docs, tutorials: http://www.blynk.cc
  int BlynkCon = 0;
  while (BlynkCon == 0) {
    Serial.print ("\nBlynk connect ... ");
    BlynkCon=Blynk.connect();
    if (BlynkCon == 0) {
      Serial.println("failed, try again");
      delay(1000);
    }
  }
  Serial.println("connected");
}
void loop() { // Kontinuierliche Wiederholung 
  Blynk.run();// Blynk Housekeeping
  IAQ = iaqSensor.iaq ;
  Serial.print(":"+String(String(IAQ)));
  Serial.println();
  Blynk.virtualWrite(1,IAQ);// Wert an Blynk-Server übermitteln
  Blynk.run();// Blynk Housekeeping
  delay( 5000 );
}

More Octopus tutorials :

  • Connect the Octopus with the internet and transfer data.
  • Octopus and MacOS
  • Send data from the Octopus, with Thingspeak.

Schlagwörter: , , , , , ,

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Abmelden /  Ändern )

Google Foto

Du kommentierst mit Deinem Google-Konto. Abmelden /  Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden /  Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Abmelden /  Ändern )

Verbinde mit %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.


%d Bloggern gefällt das: