Blynk 2.0 Wifi issue

This is a continuation of the thread here: Convert to Blynk 2.0 Problem - #13 by DominicDecoco

I cannot hardcode my wifi credentials into a sketch in the Particle IDE and get the sketch to compile. I get an error on line 22, Blynk.begin() if I add in anything (even empty quotation marks) to that line past an auth code. The error is always the same,
invalid conversion from 'char*' to 'uint16_t' {aka 'short unsigned int'} [-fpermissive]
I used this code before in Blynk 1.0, but I used Wifi provisioning and did not hardcode it. Since Wifi provisioning is not supported anymore for Particle boards I need to figure this out. Complete code follows:


#define BLYNK_TEMPLATE_ID "xxx"
#define BLYNK_DEVICE_NAME "Garage door opener"
#define BLYNK_PRINT Serial
#include <blynk.h>
#include <SparkCorePolledTimer.h>
#define BLYNK_AUTH_TOKEN "token"// Blynk authorization number for this project
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "homewifi";  // Enter your Wifi Username
char pass[] = "password";

SparkCorePolledTimer updateTimer(1000); //Create a timer object and set it's timeout in milliseconds
void doorStatus(void);

const int doorUP = D5;//set the door up switch to digital pin 5
const int doorDOWN = D6;//set the door down switch to digital pin 6
int doorUPswitch = 0;//variable to track the door open switch
int doorDOWNswitch = 0;//variable to track the door closed switch
int Timer = 0;//set the timer to 0 to start

void setup() {
    Blynk.begin(auth, ssid, pass);
    Serial.begin(9600);
    pinMode(D0, OUTPUT);//Set all the output pins for the program
    pinMode(D2, OUTPUT);
    pinMode(D3, OUTPUT);
    pinMode(doorUP, INPUT_PULLDOWN);//Set the initial status of the magnetic switch digital pin so it doesn't float
    pinMode(doorDOWN, INPUT_PULLDOWN);//set the initial status of the magnetic switch digital pin so it doesn't float
    updateTimer.SetCallback(doorStatus);
}

void doorStatus(void)
{
    doorUPswitch = digitalRead(doorUP); //Read the magnetic switch to see if the door is open
    if (doorUPswitch == HIGH){ //If the door is open 
        Blynk.virtualWrite(2,255); //light up the blynk LED
        Timer++; //Take a time step
    }
    else {
        Blynk.virtualWrite(2,0); //turn the Blynk LED off
        Timer = 0;//reset the timer
        }
        
    doorDOWNswitch = digitalRead(doorDOWN);   
    if (doorDOWNswitch == HIGH){ //If the door is closed
        Blynk.virtualWrite(3,255); //light up the blynk LED
        Timer++; //Take a time step
    }
    else {
        Blynk.virtualWrite(3,0);//turn the Blynk LED off
        Timer = 0;//reset the timer
        }
}

void loop() {
    Blynk.run();//run it 
    updateTimer.Update();
}

I’d recommend using ESP32 instead of particle boards. It’s cheaper, faster, has more GPIO pins, more popular, and widely supported.

2 Likes

I tend to agree with @John93
The reason I wasn’t able to help you any further in your original topic is that I’m not familiar with your hardware and the library that is being used with Blynk.

I’m sure there is a way to get your board working with Blynk IoT, but when you use niche hardware there is a limited pool of people who have experience with it.

The ESP32 is cheap and versatile, and widely used because of that.

Pete.

1 Like

I successfully use Particle Photons with Blynk IoT. Which Particle board are you using?

People on this forum will tell you that the three Blynk #defines MUST be the first three lines in your sketch, as you did. But I have found that if I have certain #includes after the #defines, it causes a type mismatch as you are experiencing. Try placing this line:

#include <SparkCorePolledTimer.h>

before the three Blynk #defines instead of after.

Thanks for the tip, it is a Photon. I’ll try it the next opportunity I get.

I just tried the potential solution I previously proposed and it does not work in this case. I should have tried it before I threw it out there. Sorry about that.

However, I tried the following and it successfully compiled. First, delete these lines:

char ssid[] = "homewifi";  // Enter your Wifi Username
char pass[] = "password";

Next, change this:

Blynk.begin(auth, ssid, pass);

to this:

 WiFi.setCredentials("homewifi","password");
 Blynk.begin(auth);

Be aware you may not need to include the credentials in your sketch. The Photon remembers the last five sets of credentials it used.

That worked! Thank you very much for your help! I was pretty upset when I thought my whole inventory of Photons was going to be useless for Blynk.