Particle Photon showing offline using new Blynk

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);

You’ve not moved this to the top of your code!!

Pete.

Unless it’s changed (I don’t use Blynk anymore) you need to make sure these two lines are at the very top of your code. See my example above Particle Photon showing offline using new Blynk - #4 by Tinker

It has changed. These lines of code were what triggers the early bearskins of the IoT library to compile the code so that it would use the IoT servers rather than the Legacy ones. Now that the Legacy servers have been decommissioned the latest version of the Blynk library defaults to using the IoT servers, so these lines no longer need to be at the top of the sketch.

In my opinion it’s still good practice to copy/paste the three lines of firmware configuration code at the top of the sketch, except in this case, where it seems that #include <blynk.h> needs to be at the top of the sketch.

Pete.