Particle Photon showing offline using new Blynk

I’ve been using the older Blynk for sometime, wanted to try the new version but am stumbling at the first stage of actually getting the device to show “Online”

To debug, I created a new Project in build.particle.io with the following code and added the blynk 1.0.0 library;

#define BLYNK_PRINT Serial // Defines the object that is used for printing
#define BLYNK_DEBUG        // Optional, this enables more detailed prints
#include <blynk.h>
#define BLYNK_TEMPLATE_ID "myID"
#define BLYNK_DEVICE_NAME "myDEVICE"

//char auth[] = "myAUTH1"; // BLNK 0.6.4
char auth[] = "myAUTH2";  // BKNK 2.0

//WidgetLED GarageLED(V15);

void setup()
{
    Serial.begin();   
    WiFi.clearCredentials();
    WiFi.setCredentials("mySSID", "myPASS");
    delay(2000); // Allow board to settle
    Blynk.begin(auth);
}

void loop()
{
  Blynk.run();
  
//  GarageLED.on();
  Serial.printlnf("led_ON");
  delay(2000);
//  GarageLED.off();
  Serial.printlnf("led_OFF");
  delay(2000);
}

I created a Template in the iOS Blynk app, and a device using the Blynk.Console webpage. Flashed the Photon with all the correct “myXXX” credentials, but it always shows as ‘Offline’ both in the iOS app and on the above webpage.

If I switch to my old auth code (for Blnk 0.6.4) the Photon connects okay. What am I missing? Is blynk 1.0.0 the correct library?

@Tinker please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

To futher debug, I’ve changed the code to the above, when looking at serial output for AUTH1 it shows:

   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v1.0.0 on Particle Photon

[12526] Connecting to blynk-cloud.com:80
[12580] <[1D|00|01|00] [myAUTH1]
[12611] >[00|00|01|00|C8]
[12611] Ready (ping: 30ms).

If I then switch out to AUTH2 i.e. the AUTH code copied from Blynk Console / AUTH TOKEN, I get this message

[12521]
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v1.0.0 on Particle Photon

[12522] Connecting to blynk-cloud.com:80
[12575] <[1D|00|01|00] [myAUTH2 here]
[12856] >[00|00|01|00|09]
[12856] Invalid auth token

I read somewhere that v2.0 should be connecting to blynk.cloud not as above, how do I proceed from here? - I’ve tried deleting the device (twice) and copying the new AUTH codes but get the same problem. If the library should be connecting to blynk.cloud for v2.0 does it need to be specified somewhere?

This is the Blynk 1.0.0 library used in the Particle IDE

Okay, after scanning through the library code, figured out that it looks at blynk.cloud if it finds #define BLYNK_TEMPLATE_ID in the code. I therefore rearranged the order so that is higher up [as below] and it now connects to blynk.cloud and shows online! :slight_smile:

#define BLYNK_PRINT Serial // Defines the object that is used for printing
#define BLYNK_DEBUG        // Optional, this enables more detailed prints
#define BLYNK_TEMPLATE_ID "myID"
#define BLYNK_DEVICE_NAME "myNAME"

// This #include statement was automatically added by the Particle IDE.
#include <blynk.h>

Hopefully this may help others having the same issue!? - Now my Pro trial has expired before I even managed to get online! :frowning: Any chance of another @Pavel for finding a bug? :slight_smile: :grinning:

2 Likes

This helped me big time, thank you for posting the solution!

1 Like

@Tinker Thanks this really helped me! I have Particle Argon and Boron devices and was really struggling with the new Blynk 2.0. It really helped clear up some mass confusion I had as well. Once I realized that the Legacy and the New Blynk both use the same exact library. Only a line of code determines which system it is using. I was having a hard time wrapping my head around how to get Blynk.Edgent to work with Particle Cloud and the way the Particle devices are provisioned via their own app. The simple fix - you don’t use Blynk.Edgent with these devices being they have their own cloud system for provisioning and OTA updates.

Now I also understand how the new Blynk 2.0 can still easily work with just about every board the old Blynk did. Fantastic! Kudos to you! :wink:

@PeteKnight @vshymanskyy Thanks to @Tinker post with the similar problem I have it all figured out now. Switching to the new Blynk from the old is going to be easy now… and I paid for the year of the plus plan. :slight_smile: :+1:

2 Likes

not working for me unfortunately. Even having made the change to the code as suggested, I still get:

[744688] Connecting to blynk-cloud.com:80
[745180] <[02|00|01|00] ************************Jz_YHVzJ9B6
[745672] >[00|00|01|00|09]
[745673] Invalid auth token

@tpstech please post your full sketch, correctly formatted with triple backticks at the beginning and end.
Triple backticks look like this:
```

Pete.

#define BLYNK_PRINT Serial  // Set serial output for debug prints
// set Template ID and Device Name for Blynk 2.0
#define BLYNK_TEMPLATE_ID "***********"
#define BLYNK_DEVICE_NAME "BoronLumina"
#define BLYNK_DEBUG       // Uncomment this to see detailed prints
#define BLYNK_HEARTBEAT 300
#define PARTICLE_KEEPALIVE 120
#include <blynk.h>

char auth[] = "**********************";

BLYNK_WRITE(V1)
{
    if (param.asInt() == 1){
        digitalWrite(A0,HIGH);
        delay(50);
        digitalWrite(A0, LOW);
        digitalWrite(7, HIGH);
        digitalWrite(A2, HIGH);
    }
    else{
        digitalWrite(A0,LOW);
        digitalWrite(A2, HIGH);
        digitalWrite(7, LOW);
        delay(50);
        digitalWrite(A2, LOW);
        digitalWrite(7,HIGH);
        delay(100);
        digitalWrite(7,LOW);
        delay(100);
        digitalWrite(7,HIGH);
        delay(100);
        digitalWrite(7,LOW);
    } 
    
}

BLYNK_WRITE(V2)
{
    bool pinState = digitalRead(7);
    if (!pinState){
        if (param.asInt() == 1){
            digitalWrite(A0,HIGH);
            delay (50);
            digitalWrite(A0, LOW);
            delay (500);
            digitalWrite(A2, HIGH);
            delay(50);
            digitalWrite(A2, LOW);
        }
        digitalWrite(A0,LOW);
        digitalWrite(A2, LOW);
    }
}


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

  delay(5000); // Allow board to settle
  pinMode (7,OUTPUT);
  pinMode (A0, OUTPUT);
  pinMode (A2, OUTPUT);
  digitalWrite (7, LOW);
  digitalWrite (A0, LOW);
  digitalWrite (A2, LOW);
  Blynk.begin(auth);
}

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

What Blynk library version are you using?

Pete.

0.5.4. I didn’t consider that. I’ve just updated it to 1.0.0 but it still gives me the same result.

The latest version is 1.0.1

I have no experience (and therefore no interest) in the Particle boards, and this means I don’t pay much attention to Particle related issues.
But, I think you need to define your WiFi credentials in the sketch…

Pete.

If using build.particle IDE, check it hasn’t added the #include <blynk.h> line again at the top of your code after updating the library! (That has to be AFTER the TEMPLATE_ID and DEVICE lines for it to pick up the correct cloud)

Directly from the docs and release notes:

@vshymanskyy Its good to see the docs have been updated to make it clearer, however, as Particle automatically adds the #include <blynk.h> to the very top of the code, it’s VERY easy to get this problem, even if you read the docs originally.

To prevent it happening, I would highly recommend the library be modified to allow for the template ID lines to be located after the blynk.h line!

This is impossible, unfortunately. We will modify Particle examples so it’s even more clear.

Okay I decided to give it another crack this morning and found that although I don’t have a #include <blynk.h> at the top of my sketch, by moving the #define BLYNK_TEMPLATE_ID line to the very top (above the #define BLYNK_PRINT Serial I got it to work. Thanks chaps. Now to understand how to set it up and use in Blynk 2.0 :laughing:

1 Like

This was my problem in January 2023. I finally migrated my Particle hobby project to the new Blynk server. It has been about four years since I originally set it up, so I was rusty and had trouble getting my device to connect.

In my case, I don’t use Blynk to connect to WiFi. Instead, I let the Particle device do that.

I deleted my old iPhone Blynk app and started over by installing the new app on my iPhone.

As far as the Particle application goes, I think I really needed very minimal changes.

First, I created a new program(/sketch). Then, I had to add the Blynk library by searching for it (I use the Particle web ide).

However, the key to making it work was to make sure the #define statements were before the #include <blynk.h> statement! This was the key to making it work.

Once that was corrected, and, my auth token updated, my device was recognized as online in the Blynk dashboard. From there, I could configure my Blynk iOS app.

Here’s a brief outline of my code:

#define BLYNK_TEMPLATE_ID "TMPxxx"
#define BLYNK_DEVICE_NAME "Controller"
#define BLYNK_AUTH_TOKEN  "xxx"

// This #include statement was automatically added by the Particle IDE.
#include <blynk.h>

char auth[] = BLYNK_AUTH_TOKEN;

//define other app variables
bool    tankFull;
BlynkTimer  timer;

BLYNK_CONNECTED()
{
// I commented all of this out.  it's an empty function for me
}

void UpdateBlynk()
{
    // this function sends data back to Blynk's virtual pins for use in the app
    Blynk.virtualWrite(V4, tempF);
    
    if (digitalRead(D3) == HIGH)
        Blynk.virtualWrite(V3, 255);
    else
        Blynk.virtualWrite(V3, 0);
}

void setup()
{
   // declare Particle API calls.   this is unique to your application
    Particle.function("digitalOut", digitalOut);

    Particle.variable ("TankFull", tankFull);

    pinMode (D3, OUTPUT);

    delay(5000); // Allow board to settle

    Blynk.config(auth);
    timer.setInterval(1000, UpdateBlynk);   // call this function every second to update Blynk with status
}

void loop()
{
    // define local variables here
    byte    i;     // loop counter
    
    // read Particle inputs -----------------------------------------------------
     
    // process inputs -----------------------------------------------------------

    if (analogRead(A1)<100)
         tankFull = true;
      else
         tankFull=false;        


    // process actions ---------------------------------------------------------
    
    if (digitalRead(D3) == HIGH && tankFull == true) {
        Particle.publish ("safety-off", "D3 turned off b/c tank full", PRIVATE);
        digitalWrite (D3, LOW);
    }

    
    // set/comm outputs --------------------------------------------------------
    // display output ----------------------------------------------------------
    
   // call system functions

    Blynk.run();
    timer.run();

}   // main loop

In fact, looking at some older revisions, putting the Blynk #define first was required in the new system. This was not needed in the past… it appears that this is the only change required on the Particle side.