How to write/read different pins defined on the spiff?

I am building a code that will let the user to ( without any config button )

power on the device ( esp8266 + 2 rele ) and get a captive portal
from there set up ssid/pass/auth token, save
then the device will connect to the wifi network and connect to blink

Up to here, its done, its working just fine. But in the future if I want to add a second device ( 2 rele output) and use the same token to build under the same project 2 different buttons and have 4 buttons for 2 devices, 2 rele each, V1 V2 V3 V4 , I need to define some way in my code that each chanel of each board will be subscribed to a specific Virtual Pin, and this is my problem

I already know how to build the website, save the spiff, read a json file, and parse it to get the Int value, but that I dont know is how to define that under de Blynk library

At the moment I am using arduino IDE and I am using this way to define a code outside the setup / loop

I would need some way to put this code inside the setup function

BLYNK_WRITE(20) {
if (param.asInt()) {
//HIGH
digitalWrite(2, LOW);
} else {
//LOW
digitalWrite(2, HIGH);
}
}

Because I will need to NOT hardcode the “20” value, I already have a variable called
int VirtualPinChanelA = myspiff::loadspiff("/ch1.txt").toInt(); but If I use the BLYNK_WRITE definition inside the setup it fails

I think the only tool that will work for you is BLYNK_WRITE_DEFAULT()
This returns a parameter which tells you which virtual pin was the source of the BLYNK_WRITE command.

I used it in this example as a neat(ish) way to streamline my code.

Pete.

2 Likes

And if I subscribe to all posible virtual pins, and conpare “only” the onde defined in my code and “copy” the value of those to the pins that I would like to control, it could be a a workarround …

Your explanation of the solution doesn’t make that much sense to me, but I’d suggest that you do some experimentation and take it from there.

Pete.