Teensy 4.1 freezes when Connected to local Blynk server

Hi

this is my first time using Blynk. I have been trying for days now to get it to work,but am unable to.

I am using a Teensy 4.1 with the built in Ethernet controller for a hard wired network connection. I am using a local server.

I get the same results as the following user My project offline

The serial monitor shows that it is connected and ready

Start NativeEthernet_WM_Config_Teensy on TEENSY 4.1 with Teensy 4.1 NativeEthernet Library

BlynkEthernet_WM v1.5.0

=========================

Default SPI pinout:

MOSI:11

MISO:12

SCK:13

SS:10

=========================

setCsPin:10

test1

[621] MAC:***************

[8784] IP:172.16.1.85

[8784] 

    ___  __          __

   / _ )/ /_ _____  / /__

  / _  / / // / _ \/  '_/

 /____/_/\_, /_//_/_/\_\

        /___/ v1.0.0 on TEENSY 4.1



[8785] Connecting to 172.16.1.34:8080

[8795] Ready (ping: 9ms).

and in the log of my local server

18:45:06.401 DEBUG- completeLogin. [id: 0xd9b91bbf, L:/172.16.1.34:8080 - R:/172.*.*.*:49153]
18:45:06.402 INFO - *************@shaw.ca hardware joined.
18:45:06.470 DEBUG- Changing read timeout interval to 104

I have tried using blynk.connect instead of blynk.begin. no success

tried with and without Use_Blynk_wm, with and without use_local_server, and setting the server credentials to match my local server, thinking that it might be applying settings somewhere else.

the farthest I can get is showing Ready.

I am using an android phone, setup a project and got the keys. if I change the keys in the sketch, it shows that the key does not match. so I know it is connecting to the project.

in that other thread, he said to look thru examples, etc. I can not find any examples of a teensy4.1 using onboard ethernet to a local server. I started with the NativeEthernet_WM_config_Teensy. and tried other sketches in the BlynkEthernet_manager library, but am unable to get any farther than this

is anyone able to help?

Thanks

Brent


#include <SPI.h>

#include "defines.h"
#include "Credentials.h"
char auth1[] = "****";
char server1[] = "172.16.1.34";
 #define port1    8080

//unsigned int localIP = "172.16.1.25";
byte mac[] = {0x**,0x**,0x**,0x**,0x**,0x**};
IPAddress ip (172,16,1,25);
IPAddress dns (172,16,1,254);
IPAddress gateway (172,16,1,254);
IPAddress subnet (255,255,255,0);

BlynkTimer timer;

#if USE_BLYNK_WM
  
  #include "dynamicParams.h"

  #define BLYNK_PIN_FORCED_CONFIG           V10
  #define BLYNK_PIN_FORCED_PERS_CONFIG      V20

// Use button V10 (BLYNK_PIN_FORCED_CONFIG) to forced Config Portal
BLYNK_WRITE(BLYNK_PIN_FORCED_CONFIG)
{ 
  if (param.asInt())
  {
    Serial.println( F("\nCP Button Hit. Rebooting") ); 

    // This will keep CP once, clear after reset, even you didn't enter CP at all.
    Blynk.resetAndEnterConfigPortal(); 
  }
}

// Use button V20 (BLYNK_PIN_FORCED_PERS_CONFIG) to forced Persistent Config Portal
BLYNK_WRITE(BLYNK_PIN_FORCED_PERS_CONFIG)
{ 
  if (param.asInt())
  {
    Serial.println( F("\nPersistent CP Button Hit. Rebooting") ); 
   
    // This will keep CP forever, until you successfully enter CP, and Save data to clear the flag.
    Blynk.resetAndEnterConfigPortalPersistent();
  }
}

#endif

void readAndSendData()
{
  float temperature = 25.5;
  float humidity    = 50.0;

  if (Blynk.connected())
  {
    if (!isnan(temperature) && !isnan(humidity))
    {
      Blynk.virtualWrite(V17, String(temperature, 1));
      Blynk.virtualWrite(V18, String(humidity, 1));
    }
    else
    {
      Blynk.virtualWrite(V17, F("NAN"));
      Blynk.virtualWrite(V18, F("NAN"));
    }
  }

  // Blynk Timer uses millis() and is still working even if WiFi/Blynk not connected
  Serial.print(F("R"));
}

void heartBeatPrint()
{
  static int num = 1;

  if (Blynk.connected())
    Serial.print(F("B"));
  else
    Serial.print(F("F"));

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

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

#define STATUS_CHECK_INTERVAL     60000L

  // 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))
  {
    heartBeatPrint();
    checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL;
  }
}

void setup()
{
  // Debug console
  Serial.begin(9600);
  while (!Serial);

  delay(200);
  
  Serial.print(F("\nStart NativeEthernet_WM_Config_Teensy on ")); Serial.print(BOARD_NAME);
  Serial.print(F(" with ")); Serial.println(SHIELD_TYPE);
  
#if USE_BLYNK_WM 
  Serial.println(BLYNK_ETHERNET_WM_VERSION);
#endif

  pinMode(SDCARD_CS, OUTPUT);
  digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card

  #if USE_ETHERNET_WRAPPER

    EthernetInit();

  #else

    #if USE_ETHERNET
      Serial.println(F("=========== USE_ETHERNET ==========="));
    #elif USE_ETHERNET2
      Serial.println(F("=========== USE_ETHERNET2 ==========="));
    #elif USE_ETHERNET3
      Serial.println(F("=========== USE_ETHERNET3 ==========="));
    #elif USE_ETHERNET_LARGE
      Serial.println(F("=========== USE_ETHERNET_LARGE ==========="));
    #elif USE_ETHERNET_ESP8266
      Serial.println(F("=========== USE_ETHERNET_ESP8266 ==========="));
    #else
      Serial.println(F("========================="));
    #endif
   
      Serial.println(F("Default SPI pinout:"));
      Serial.print(F("MOSI:")); Serial.println(MOSI);
      Serial.print(F("MISO:")); Serial.println(MISO);
      Serial.print(F("SCK:"));  Serial.println(SCK);
      Serial.print(F("SS:"));   Serial.println(SS);
      Serial.println(F("========================="));
           
      // unknown board, do nothing, use default SS = 17
      #ifndef USE_THIS_SS_PIN
        #define USE_THIS_SS_PIN   17    // For other boards
      #endif
           
      Serial.print(F("setCsPin:"));
      Serial.println(USE_THIS_SS_PIN);
  
      // For other boards, to change if necessary
      #if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 )
        // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries
  
        Ethernet.init (USE_THIS_SS_PIN);
  
      #elif USE_ETHERNET3
        // Use  MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer
        #ifndef ETHERNET3_MAX_SOCK_NUM
          #define ETHERNET3_MAX_SOCK_NUM      4
        #endif
        
        Ethernet.setCsPin (USE_THIS_SS_PIN);
        Ethernet.init (ETHERNET3_MAX_SOCK_NUM);
                        
      #endif  //( USE_ETHERNET || USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE ) 
  
  #endif  //USE_ETHERNET_WRAPPER



#if USE_BLYNK_WM
  Serial.println("test1");
//  Blynk.config(auth1, server1,port1);
//  Blynk.connect();
//  Blynk.begin(auth1, server1,port1, ip, dns, gateway, subnet, mac);
  Blynk.begin(auth1, server1,port1);
//Blynk.begin("TMPLLAiTnlZf", "blynk-cloud.com");
  Serial.println("test2");
#else
  Blynk.begin(auth1, server1,port1, ip, dns, gateway, subnet, mac);
#if USE_LOCAL_SERVER
  //Blynk.begin(auth, server, BLYNK_SERVER_HARDWARE_PORT);
#else
 // Blynk.begin(auth);
  // You can also specify server:
  //Blynk.begin(auth, server, BLYNK_SERVER_HARDWARE_PORT);//
#endif
#endif

  if (Blynk.connected())
  {
    #if USE_BLYNK_WM    
    Serial.print(F("Conn2Blynk: server = "));
    Serial.print(Blynk.getServerName());
    Serial.print(F(", port = "));
    Serial.println(Blynk.getHWPort());
    Serial.print(F("Token = "));
    Serial.print(Blynk.getToken());
    Serial.print(F(", IP = "));   
#else
    Serial.print(F("Conn2Blynk: server = "));
    Serial.print(server);
    Serial.print(F(", port = "));
    Serial.println(BLYNK_SERVER_HARDWARE_PORT);
    Serial.print(F("Token = "));
    Serial.print(auth);
    Serial.print(F(", IP = "));       
#endif    
    Serial.println(Ethernet.localIP());
  }

  timer.setInterval(60000L, readAndSendData);
}

#if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS)
void displayCredentials()
{
  Serial.println("\nYour stored Credentials :");

  for (uint8_t i = 0; i < NUM_MENU_ITEMS; i++)
  {
    Serial.println(String(myMenuItems[i].displayName) + " = " + myMenuItems[i].pdata);
  }
}

void displayCredentialsInLoop()
{
  Serial.println("test");
  static bool displayedCredentials = false;

  if (!displayedCredentials)
  {
    for (uint8_t i = 0; i < NUM_MENU_ITEMS; i++)
    {
      if (!strlen(myMenuItems[i].pdata))
      {
        break;
      }

      if ( i == (NUM_MENU_ITEMS - 1) )
      {
        displayedCredentials = true;
        displayCredentials();
      }
    }
  }
}
#endif

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

#if (USE_BLYNK_WM && USE_DYNAMIC_PARAMETERS)
  displayCredentialsInLoop();
#endif 
}

You should be using library version 0.6.1

I think I’d also start with a simpler sketch.

Pete.

Hi Pete

Thanks for that information and the very quick reply!

I changed to 0.6.1, no change

If I try to open BlynkBlink sketch from the 0.6.1 library, it will run but will get a DHCP failure.

if I change the blynk.begin to include the local ip/subnet/etc
Blynk.begin(auth1, server1,port1, ip, dns, gateway, subnet, mac);

on the serial console it shows my IP is 0.0.0.0

change the Ethernet.h to nativeethernet.h, I get a huge number of errors on compiling. so seems like I need to run ethernet.h, but from what I read I need nativeethernet.h.

seems wierd that no one has any examples of a Teensy 4.1 with native ethernet with a local server anywhere… I would love to have a working sketch that I could start from.

I just noticed my like to another thread that had a similar issue was incorrect. below is the link of someone having the same issue, but no way of correcting the issue was given other than looking thru documentation, etc. I have been scouring thru the documentation and forums, and have been unable to find anything. again, seems like almost everyone is using other hardware.

Thanks

Brent

Was able to get a very basic program to work on a ESP8266 GetData from the Blynk example. now going to work on getting the same program to work on the Teensy 4.1

Still unable to get the teensy 4.1 to work. it always gets stuck on the blynk.begin. I can put a Serial.println right after the blynk.begin, and it will never send it. even though in the serial monitor it is saying connected and ready, identical to what the ESP8266 was showing. so there must be an error or something in the library for the teensy4.1 to work with the built in ethernet and blynk?

you can see the link to a previous thread above which shows the libraries that are supposed to work with blynk. maybe I will just have to use a wiznet jack instead now. figured using the 4.1 with the built in ethernet would be a good thing…

Thanks

Brent

I’m afraid that you didn’t install the libraries or the Teensy core patches correctly. I have to say that Teensy core NativeEthernet is still not matured, have lots of issues so that I’m thinking about drop its support for many libraries.

Anyway, it’s still working, connecting to local server after correctly installing all the necessary patches. I’m using Teensy core v1.54b10 and Arduino v1.8.15

Start NativeEthernet_WM_Config_Teensy on TEENSY 4.1 with Teensy 4.1 NativeEthernet Library
BlynkEthernet_WM v1.5.0
=========================
Default SPI pinout:
MOSI:11
MISO:12
SCK:13
SS:10
=========================
setCsPin:10

EEPROM size = 4284, start = 0
Flag read = 0xD0D04321
No doubleResetDetected
SetFlag write = 0xD0D01234
[3556] ======= Start Default Config Data =======
[3556] Hdr=NonSSL,BName=Teensy_W5500
[3556] Svr=192.168.2.112,Tok=token
[3556] Svr1=blynk-cloud.com,Tok1=<<my real Blynk auth>>
[3556] Prt=8080,SIP=
[3556] i=0,id=mqtt,data=default-mqtt-server
[3556] i=1,id=mqpt,data=1883
[3556] i=2,id=user,data=default-mqtt-username
[3556] i=3,id=mqpw,data=default-mqtt-password
[3556] i=4,id=subs,data=default-mqtt-SubTopic
[3556] i=5,id=pubs,data=default-mqtt-PubTopic
[3556] Save,WCSum=0x2153
[3558] CrCCSum=0x29a6
[3558] ======= Start Loaded Config Data =======
[3558] Hdr=W5X00,BName=Teensy_W5500
[3558] Svr=192.168.2.112,Tok=token
[3558] Svr1=blynk-cloud.com,Tok1=<<my real Blynk auth>>
[3558] Prt=8080,SIP=
[3558] i=0,id=mqtt,data=default-mqtt-server
[3558] i=1,id=mqpt,data=1883
[3558] i=2,id=user,data=default-mqtt-username
[3558] i=3,id=mqpw,data=default-mqtt-password
[3558] i=4,id=subs,data=default-mqtt-SubTopic
[3558] i=5,id=pubs,data=default-mqtt-PubTopic
[3558] MAC:FE-DD-BF-F7-9E-B2
[6195] IP:192.168.2.114
[6195] bg: noConfigPortal = true
[6195] bg:ECon.TryB
[6195] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.1 on TEENSY 4.1

[6196] BlynkArduinoClient.connect: Connecting to 192.168.2.112:8080
[6203] Ready (ping: 6ms).
[6270] Connected to Blynk Server = 192.168.2.112, Token = token
[6270] bg:EBCon
Conn2Blynk: server = 192.168.2.112, port = 8080
Token = token, IP = 192.168.2.114
B
Your stored Credentials :
MQTT Server = default-mqtt-server
Port = 1883
MQTT UserName = default-mqtt-username
MQTT PWD = default-mqtt-password
Subs Topics = default-mqtt-SubTopic
Pubs Topics = default-mqtt-PubTopic
Stop doubleResetDetecting
ClearFlag write = 0xD0D04321
RBRBRBRBRBRBRBRBRB RB  <===== the loop still running

Sorry I won’t spend time on this issue to help you. Just follow the instructions and apply the patches mentioned in Patches for Teensy boards

Teensy NativeEthernet Config Portal currently doesn’t work because of some bugs of the NativeEthernet library / Teensy core (haven’t spent time to find out yet).

You have to hardcode by modifying the Credentials.h as follows:

#define TO_LOAD_DEFAULT_CONFIG_DATA      true

#if TO_LOAD_DEFAULT_CONFIG_DATA

bool LOAD_DEFAULT_CONFIG_DATA = true;   //false;

Blynk_Configuration defaultConfig =
{
  //char header[16], dummy, not used
#if USE_SSL
  "SSL",
#else
  "NonSSL",
#endif
  // Blynk_Credentials Blynk_Creds [NUM_BLYNK_CREDENTIALS];
  // Blynk_Creds.blynk_server and Blynk_Creds.blynk_token
  //"account.duckdns.org",  "token1",
  "your-local-server",  "token",
  "blynk-cloud.com",     "<<my real Blynk auth>>",
  //int  blynk_port;
#if USE_SSL
  9443,
#else
  8080,
#endif
  // char static_IP      [16];
  //"192.168.2.230",
  // Use dynamic DHCP IP
  "",
  //char board_name     [24];
  "Teensy_W5500",
  // terminate the list
  //int  checkSum, dummy, not used
  0
  /////////// End Default Config Data /////////////
};

#else

...

Hi Khoih

Thank you very much. changing

bool LOAD_DEFAULT_CONFIG_DATA = true;

was the key to making it work.

it makes sense now. just not being familiar to it. and I did try using my browser to enter credentials on the ip address of the teensy, but as you say there is some bugs with that right now, which is why it must not have worked.

Hopefully if anyone else has this issue, they now know what to do. Thank you very much for your help with this. I am sure you get asked lots of questions all the time, and I understand why you only want to help so much.

Thanks!

1 Like

I’m glad it’s working for you now.

Next time, for complex issue like yours, it’s always better to post the issue on the corresponding library’s GitHub. By doing that way, the library author / maintainer will be aware immediately and can solve the issue faster. Luckily I’m coming across your issue today to help.