Particle Photon showing offline using new Blynk

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.

Useful info, but looking at your sketch I see a few issues…

This i variable is re-defined (and therefore zeroed) each time the void loop executes, so it cant be used to count how many times the void loop executers (assuming that was it’s purpose)

You’re reading you’re reading your analog pin and D3 digital pin (and doing the Particle.publish thing, which I don’t really know anything about) hundreds of times per second - because that’s how fast the void loop executes)

Wouldn’t it be better to put this code in your UpdateBlynk function, so it’s only execured one per second?

Also, I’m not really a great fan of this system…

#define BLYNK_AUTH_TOKEN "xxx"

char auth[] = BLYNK_AUTH_TOKEN;

Blynk.config(auth);

I know that this is how the Blynk examples are structured, but I think it’s neater to delete…

and change…

to…

Blynk.config(BLYNK_AUTH_TOKEN);

Pete.

Good suggestions!

Thank you, Pete!

1 Like

I am using particle web ide and the code from 2 years ago was working great with the old Blynk. the code is below and it does not work. Can anyone see the reason not showing online on the new Blynk. Particle shows online…

#define BLYNK_PRINT Serial
#define BLYNK_HEARTBEAT 60
//#define BLYNK_MAX_READBYTES 1024
#define    cOn 1
#define    cOff 0
#define    cAlarm 2
 
 
#define BLYNK_TEMPLATE_ID "TMPL2oAlJOxqS"
#define BLYNK_TEMPLATE_NAME "Alarm"

#define BLYNK_AUTH_TOKEN "6Qo2NSZxxxxxcYo_h7i1u6Ttw9EgeK"
//char auth[] = "232de6af9292426aacxxxxxba757e1f207fb7";

#include "Test.h"
#include <blynk.h>
 
 
char auth[] = BLYNK_AUTH_TOKEN;

@Justin_Nguyen 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:
```

Copy and paste these if you can’t find the correct symbol on your keyboard.

Pete.

@Justin_Nguyen you’ve edited your post, but only placed triple backticks at the end of your code, rather than…

Please fix this, otherwise your unformatted code will be deleted.

Pete.

It appears you overlooked this comment….

and this comment…

Pete.

Thanks Pete, the same result. Offline…
Could it be my OS version is 2.3.1
below is more details on the code.

// This #include statement was automatically added by the Particle IDE.
 
 
 
 
#define BLYNK_PRINT Serial
#define BLYNK_HEARTBEAT 60
//#define BLYNK_MAX_READBYTES 1024
#define    cOn 1
#define    cOff 0
#define    cAlarm 2
 
 
#define BLYNK_TEMPLATE_ID "TMPL2oAlJOxqS"
#define BLYNK_TEMPLATE_NAME "Alarm"

#define BLYNK_AUTH_TOKEN "6Qo2NSZIprVsa6cYo_h7i1u6Ttw9EgeK"
//char auth[] = "232de6af9292426aacba757e1f207fb7";

#include "Test.h"
#include <blynk.h>
 
 
//char auth[] = BLYNK_AUTH_TOKEN;
 


 
int PIR_PIN = A0; // Input
int AlarmEnableLed = D7;
int AlarmBuzzer    = D1;
int AlarmSiren = D4;
int AlarmTest = D5;

int iAlarmStatus = 0;
int iCount=0;
int gDegree=0;
int iStart = 1;
int iMotionCount=0;
int iAlarmTimer=0;
int iSnoozeTimer=0;
int adDress = 10; //10-20 EEprom adress. Reserve location 100 for Watch dog reset counter.
int adDressArms = 20; //EEprom adress. Reserve location Arms Flag, incase reboot by watchdog, it will arms itself again..

bool bSnooze=false;

long MIN_TIME_BETWEEN_TRIGGERS = 222;
double iResetTimer=0;
uint16_t iWdogCounter=22;
uint16_t iArmFlag=0;

 


 
ApplicationWatchdog *wd; 
void myWatchdogHandler(void);

//int led2 = D7; // Instead of writing D7 over and over again, we'll write led2
 
WidgetLED MotionLedApp(V15);
WidgetLED AlarmEnableLedApp(V13);
WidgetLED SirenLedApp(V11);

WidgetMap myMap(V0);
Servo myservo;
 
 

BLYNK_WRITE(V14){ //Cong tac bam tren phone app, chung ta thanh loc roi quet dinh (Virtual button) snooze

    int virtualbuttonclosed = param.asInt();
    
    if (virtualbuttonclosed == 1)    {
        //digitalWrite(AlarmTest, HIGH); //Mo bong den tren board dien
        bSnooze = true;
        iSnoozeTimer=0;
        SirenLedApp.off(); //Stop the Siren..
        }
    else {
        digitalWrite(AlarmTest, LOW);
        }
}

BLYNK_WRITE(V12){ //Cong tac bam tren phone app, chung ta thanh loc roi quet dinh (Virtual button)
    int iDegree = param.asInt();
    
    gDegree=iDegree;
    Blynk.virtualWrite(V1, iDegree);
    if (iDegree >= 0 && iDegree <= 180)    {
        myservo.write(iDegree);      
        }
}

BLYNK_WRITE(V7){ //Cong tac bam tren phone app, chung ta thanh loc roi quet dinh (Virtual button)
    int virtualbuttonclosed = param.asInt();
    
    if (virtualbuttonclosed == 1 && gDegree == 180)    {
        digitalWrite(AlarmEnableLed, HIGH); //Mo bong den tren board dien
        AlarmEnableLedApp.on(); //Mo bong den tren phone's app.
        iAlarmStatus = cOn;
        iMotionCount=0;
        bSnooze=false;
        writeToEEPROM(adDressArms, 1); //Arm Flag
        }
    else if (gDegree == 180) {
        digitalWrite(AlarmEnableLed, LOW);
        digitalWrite(AlarmSiren, LOW);         // Tat May hu (Siren)
        AlarmEnableLedApp.off(); //Tat bong den tren board dien.
        iAlarmStatus = cOff;
        SirenLedApp.off();      //Reset the alarm LED on the phone.
        iAlarmTimer=0; //
        bSnooze=false;
        iMotionCount=0;
        iResetTimer=0;
        writeToEEPROM(adDressArms, 0); //Disarm flag
        }
}

void setup() {
    
    int index = 1;

    loveMake++;
    Serial.begin(9600);
    //Blynk.begin(auth);
    delay(5000); // Allow board to settle
   //Blynk.begin(BLYNK_AUTH_TOKEN);
    Blynk.config(BLYNK_AUTH_TOKEN);