Blynk Support for Teensy and Mega boards running ESP8266 AT-command WiFi shields

khoih-prog

Well-known member
https://github.com/khoih-prog/Blynk_Esp8266AT_WM

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.

Blynk_Architecture.png

The following is the example code for Teensy 4.0 and the debug terminal output


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

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

#ifdef CORE_TEENSY
  // For Teensy 4.0
  #define EspSerial Serial2   //Serial2, Pin RX2 : 7, TX2 : 8
  #if defined(__IMXRT1062__)
    #define BOARD_TYPE      "TEENSY 4.0"
  #else
    #define BOARD_TYPE      BLYNK_INFO_DEVICE
  #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     48

#define USE_BLYNK_WM      true
//#define USE_BLYNK_WM      false

#if USE_BLYNK_WM
  #ifdef CORE_TEENSY
    #include <BlynkSimpleShieldEsp8266_Teensy_WM.h>
  #else
    #include <BlynkSimpleShieldEsp8266_WM.h>
  #endif
#else
  #include <BlynkSimpleShieldEsp8266_Teensy.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();
}


1. No Config Data => Config Portal


Code:
Start Blynk WiFiManager using ESP8266_AT_Shield on TEENSY 4.0
Start Blynk_WM
[7866] AT version:0.40.0.0(Aug  8 2015 14:45:58)
SDK version:1.3.0
Ai-Thinker Technology Co.,Ltd.
Build:1.3.0.2 Sep 11 2015 11:48:04
OK
[8392] Init new EEPROM, size = 1080
[8393] bg: No configdat. Stay forever in config portal
[12836] startConfig: SSID = Teensy4_CCE61, PW = MyTeensy4_CCE61, IP = 192.168.100.1

2. Config Data Ready => Run and AutoReconnect

Code:
Start Blynk WiFiManager using ESP8266_AT_Shield on TEENSY 4.0
Start Blynk_WM
[7866] AT version:0.40.0.0(Aug  8 2015 14:45:58)
SDK version:1.3.0
Ai-Thinker Technology Co.,Ltd.
Build:1.3.0.2 Sep 11 2015 11:48:04
OK
[8390] Header = SHD_ESP8266, SSID = ****, PW = ****
[8390] Server = ****.duckdns.org, Port = 8080, Token = ****
[8390] Board Name = Teensy4-WM
[8390] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.1 on Teensy 4.0

[8390] con2WF: start
[8390] connectToWifi: Try connectWiFi
[8390] Connecting to ****
[14956] AT version:0.40.0.0(Aug  8 2015 14:45:58)
SDK version:1.3.0
Ai-Thinker Technology Co.,Ltd.
Build:1.3.0.2 Sep 11 2015 11:48:04
OK
[15493] Get macAddress = 5c:cf:7f:66:05:d2
[22526] IP = 192.168.2.107

[22543] Connected to WiFi
[22543] con2WF: con OK
[22543] IP = 192.168.2.107

[22560] bg: WiFi connected. Try Blynk
[32717] Ready (ping: 18ms).
[32932] bg: WiFi+Blynk connected
BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB 
F[634808] run: Blynk lost. Connect Blynk
F[649868] run: Blynk lost. Connect Blynk
F[664928] run: Blynk lost. Connect Blynk
[675040] Ready (ping: 13ms).
[675265] run: Blynk reconnected
BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB BBBBBBBBBB
 
Last edited:
Back
Top