-->
Page 1 of 1

BlynkManager for Mega/Teensy/SAMDUE/SAMD/STM32 & ESP8266_AT

PostPosted: Tue Feb 18, 2020 12:54 am
by khoih-prog
https://github.com/khoih-prog/Blynk_Esp8266AT_WM

You can install directly from Arduino Library Manager

https://www.ardu-badge.com/Blynk_Esp8266AT_WM


To help you to eliminate `hardcoding` your Wifi and Blynk credentials for Mega/Teensy boards running ESP8266 AT shields, and updating/reflashing every time when you need to change them. Configuration data are saved in configurable location in EEPROM.

With version `v1.0.0` or later, you now can configure:

1. `Config Portal Static IP address, Name and Password.`
2. `Static IP address, Gateway, Subnet Mask and 2 DNS Servers IP addresses.`


This is the library designed to help you eliminate hardcoding your WiFi and Blynk Credentials in Teensy (3.x, 4.0) and Arduino Mega 1280, Mega 2560 boards using ESP8266 AT-command WiFi shields.

You can update Blynk Credentials any time you need to change via Configure Portal. Data are saved in configurable locations in EEPROM.

This is the link to Blynk

http://docs.blynk.cc

Blynk was designed for the Internet of Things. It can control hardware remotely, it can display sensor data, it can store data, visualize it and do many other cool things.

Image

You can install and use Local Blynk Server (RPi Zero W, 3B+, 4, Laptop, PC, etc) to have full control.
The Server source code is in Public Domain and written in Java. You can download, compile and use to be sure having full control.

Use Local Blynk Server

Blynk Server

Blynk Server Source Code

Re: Blynk & WiFiManager for Mega/Teensy/SAMD & ESP8266 shiel

PostPosted: Sun Feb 23, 2020 1:05 am
by khoih-prog
New Version v1.0.2

1. Add support to SAMD (DUE, ZERO, MKR, NANO_33_IOT, M0, M0 Pro, AdaFruit CIRCUITPLAYGROUND_EXPRESS, etc.) boards

https://github.com/khoih-prog/Blynk_Esp8266AT_WM/releases/tag/v1.0.2

Sample Code for SAMD

Code: Select all#define BLYNK_PRINT Serial

#if    ( defined(ARDUINO_SAM_DUE) || defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_MKRWIFI1010) \
      || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_SAMD_MKRFox1200) || defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) \
      || defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKRNB1500) || defined(ARDUINO_SAMD_MKRVIDOR4000) || defined(__SAMD21G18A__) \
      || defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) || defined(__SAM3X8E__) || defined(__CPU_ARC__) )     
  #if defined(ESP8266_AT_USE_SAMD)
    #undef ESP8266_AT_USE_SAMD
  #endif
  #define ESP8266_AT_USE_SAMD      true
#else
  #error This code is intended to run only on the SAMD boards ! Please check your Tools->Board setting. 
#endif

#if defined(ESP8266_AT_USE_SAMD)
// For SAMD
  #define EspSerial Serial1
 
  #if defined(ARDUINO_SAMD_ZERO)
    #define BOARD_TYPE      "SAMD Zero"
  #elif defined(ARDUINO_SAMD_MKR1000)
    #define BOARD_TYPE      "SAMD MKR1000"   
  #elif defined(ARDUINO_SAMD_MKRWIFI1010)
    #define BOARD_TYPE      "SAMD MKRWIFI1010"
  #elif defined(ARDUINO_SAMD_NANO_33_IOT)
    #define BOARD_TYPE      "SAMD NANO_33_IOT" 
  #elif defined(ARDUINO_SAMD_MKRFox1200)
    #define BOARD_TYPE      "SAMD MKRFox1200"
  #elif ( defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) )
    #define BOARD_TYPE      "SAMD MKRWAN13X0"
  #elif defined(ARDUINO_SAMD_MKRGSM1400)
    #define BOARD_TYPE      "SAMD MKRGSM1400"
  #elif defined(ARDUINO_SAMD_MKRNB1500)
    #define BOARD_TYPE      "SAMD MKRNB1500"
  #elif defined(ARDUINO_SAMD_MKRVIDOR4000)
    #define BOARD_TYPE      "SAMD MKRVIDOR4000"
  #elif defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS)
    #define BOARD_TYPE      "SAMD ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS" 
  #elif ( defined(__SAM3X8E__) || (__SAM3X8E__) || (__CPU_ARC__) )
    #define BOARD_TYPE      "SAMD Board"
  #else
    #define BOARD_TYPE      "SAMD Unknown"
  #endif
#endif

#include <ESP8266_Lib.h>

// Start location in EEPROM to store config data. Default 0
// Config data Size currently is 128 bytes)
#define EEPROM_START     256

#define USE_BLYNK_WM      true
//#define USE_BLYNK_WM      false

#if USE_BLYNK_WM
  #include <BlynkSimpleShieldEsp8266_SAMD_WM.h>
#else
  #include <BlynkSimpleShieldEsp8266_SAMD.h>

  #define USE_LOCAL_SERVER      true

  #if USE_LOCAL_SERVER
    char auth[] = "****";
    String BlynkServer = "account.duckdns.org";
    //String BlynkServer = "192.168.2.112";
  #else
    char auth[] = "****";
    String BlynkServer = "blynk-cloud.com";
  #endif

  #define BLYNK_SERVER_HARDWARE_PORT    8080

  // Your WiFi credentials.
  char ssid[] = "****";
  char pass[] = "****";
 
#endif

// Your Mega <-> ESP8266 baud rate:
#define ESP8266_BAUD 115200

ESP8266 wifi(&EspSerial);

void heartBeatPrint(void)
{
  static int num = 1;

  if (Blynk.connected())
  {
    Serial.print("B");
  }
  else
  {
    Serial.print("F");
  }
 
  if (num == 80)
  {
    Serial.println();
    num = 1;
  }
  else if (num++ % 10 == 0)
  {
    Serial.print(" ");
  }
}

void check_status()
{
  static unsigned long checkstatus_timeout = 0;

#define STATUS_CHECK_INTERVAL     15000L

  // Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to send updates frequently if there is no status change.
  if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0))
  {
    // report status to Blynk
    heartBeatPrint();

    checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL;
  }
}

void setup()
{
  // Debug console
  Serial.begin(115200);
  delay(1000);
 
  // initialize serial for ESP module
  EspSerial.begin(ESP8266_BAUD);
  Serial.println("\nStart Blynk WiFiManager using ESP8266_AT_Shield on " + String(BOARD_TYPE));

  #if USE_BLYNK_WM
    Serial.println(F("Start Blynk_WM"));
    Blynk.setConfigPortalIP(IPAddress(192, 168, 120, 1));
    //Blynk.setConfigPortal("Mega", "MyMega"); 
    Blynk.begin(wifi);
  #else
    Serial.println(F("Start Blynk"));
    Blynk.begin(auth, wifi, ssid, pass, BlynkServer.c_str(), BLYNK_SERVER_HARDWARE_PORT);
  #endif
}

void loop()
{
  Blynk.run();
  check_status();
}

Re: BlynkManager for Mega/Teensy/SAMDUE/SAMD/STM32 & ESP8266

PostPosted: Wed Mar 04, 2020 12:36 am
by khoih-prog
New Version v1.0.3

1. Add support to STM32 (STM32F1, F2, F3, F4, F7, etc) boards
2. Add clearConfigData() function.

Sample Code for STM32

Code: Select all/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

#if ( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3)  ||defined(STM32F4) || defined(STM32F7) )
  #if defined(ESP8266_AT_USE_STM32)
    #undef ESP8266_AT_USE_STM32
  #endif
  #define ESP8266_AT_USE_STM32      true
#endif

#if ( defined(ESP8266) || defined(ESP32) || defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560) || defined(CORE_TEENSY) || !(ESP8266_AT_USE_STM32) )
//#error This code is intended to run on STM32 platform! Please check your Tools->Board setting.
#endif

#if ESP8266_AT_USE_STM32
  // For STM32, you have to declare and enable coreresponding Serial Port somewhere else before using it
  #define EspSerial Serial1
 
  #if defined(STM32F0)
    #define BOARD_TYPE  "STM32F0"
    #error Board STM32F0 not supported
  #elif defined(STM32F1)
    #define BOARD_TYPE  "STM32F1"
  #elif defined(STM32F2)
    #define BOARD_TYPE  "STM32F2"
  #elif defined(STM32F3)
    #define BOARD_TYPE  "STM32F3"
  #elif defined(STM32F4)
    #define BOARD_TYPE  "STM32F4"
  #elif defined(STM32F7)
    #define BOARD_TYPE  "STM32F7" 
  #else
    #warning STM32 unknown board selected
    #define BOARD_TYPE  "STM32 Unknown" 
  #endif
#else
// For Mega
#define EspSerial Serial3
#define BOARD_TYPE      "AVR Mega"
#endif

#include <ESP8266_Lib.h>

// Start location in EEPROM to store config data. Default 0
// Config data Size currently is 128 bytes)
#define EEPROM_START     0

#define USE_BLYNK_WM      true
//#define USE_BLYNK_WM      false

#if USE_BLYNK_WM
  #if ESP8266_AT_USE_STM32
    #include <BlynkSimpleShieldEsp8266_STM32_WM.h>
  #else
    #include <BlynkSimpleShieldEsp8266_WM.h>
  #endif
#else
  #include <BlynkSimpleShieldEsp8266_STM32.h>

  #define USE_LOCAL_SERVER      true

  #if USE_LOCAL_SERVER
    char auth[] = "****";
    String BlynkServer = "account.duckdns.org";
    //String BlynkServer = "192.168.2.112";
  #else
    char auth[] = "****";
    String BlynkServer = "blynk-cloud.com";
  #endif

  #define BLYNK_SERVER_HARDWARE_PORT    8080

  // Your WiFi credentials.
  char ssid[] = "****";
  char pass[] = "****";
 
#endif

// Your Teensy <-> ESP8266 baud rate:
#define ESP8266_BAUD 115200

ESP8266 wifi(&EspSerial);

void heartBeatPrint(void)
{
  static int num = 1;

  if (Blynk.connected())
  {
    Serial.print("B");
  }
  else
  {
    Serial.print("F");
  }
 
  if (num == 80)
  {
    Serial.println();
    num = 1;
  }
  else if (num++ % 10 == 0)
  {
    Serial.print(" ");
  }
}

void check_status()
{
  static unsigned long checkstatus_timeout = 0;

#define STATUS_CHECK_INTERVAL     15000L

  // Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to send updates frequently if there is no status change.
  if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0))
  {
    // report status to Blynk
    heartBeatPrint();

    checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL;
  }
}

void setup()
{
  // Debug console
  Serial.begin(115200);
  delay(1000);
 
  // initialize serial for ESP module
  EspSerial.begin(ESP8266_BAUD);
  Serial.println("\nStart Blynk WiFiManager using ESP8266_AT_Shield on " + String(BOARD_TYPE));

  #if USE_BLYNK_WM
    Serial.println("Start Blynk_WM");
    Blynk.setConfigPortalIP(IPAddress(192, 168, 100, 1));
    //Blynk.setConfigPortal("Teensy4", "MyTeensy4"); 
    Blynk.begin(wifi);
  #else
    Serial.println("Start Blynk");
    Blynk.begin(auth, wifi, ssid, pass, BlynkServer.c_str(), BLYNK_SERVER_HARDWARE_PORT);
  #endif
}

void loop()
{
  Blynk.run();
  check_status();
}

Re: BlynkManager for Mega/Teensy/SAMDUE/SAMD/STM32 & ESP8266

PostPosted: Fri Mar 13, 2020 7:01 pm
by khoih-prog
New Releases v1.0.4

1. Add support to SAM DUE
2. Reduce html and code size for faster Config Portal response.
3. Enhance GUI.

So, how it works?
If it cannot connect to the Blynk server in 30 seconds, it will switch to `Configuration Mode`. You will see your built-in LED turned ON. In `Configuration Mode`, it starts a configurable access point, default called `Teensy4_XXXXXX`, `SAMD_XXXXXX`, `DUE_XXXXXX`,`Mega_XXXXXX` or `STM32_XXXXXX`. Connect to it using password `MyTeensy4_XXXXXX`, `MySAMD_XXXXXX`, `MyDUE_XXXXXX`, `MyMega_XXXXXX` or `MySTM32_XXXXXX`.

Image

After you connected, please, go to http://192.168.4.1 or the AP IP you specified.

Image

Enter your credentials : WiFi SSID/Password, Blynk Server, Port and Token, Board Name.

Image

Then click `Save`. After you restarted, you will see your built-in LED turned OFF. That means, it connected to your Blynk server successfully.