Return gpio state after long powerloss on esp8266 with blynk server at home

I got a blynk server on my bpi-r1(works as router in my countryhouse in Moscow district)
As a fact there is alot of power loses and all of them triggers the #куищще(reboot) and returns gpio state to default on my esp8266 connected to blynkk server. How can i held gpio state value before #куищще happens and return it to esp8266 after.
For example some kind of bash script wich can write gpio state to servers textfile and return it to esp on cron
Is there any ability to set and read gpio state from linux commandline to/from file?
May be there is a way to send http request to esp to get/change gpio state?

Hello. Could please clarify - you want to restore last value that was on ESP before outgage? If so we have a sync feature for that - http://docs.blynk.cc/#blynk-main-operations-state-syncing.

BLYNK_CONNECTED() {
  if (isFirstConnect) {
    Blynk.syncAll();
  }
}

When ESP will be rebooted it will call BLYNK_CONNECTED and Blynk.syncAll(); will trigger all BLYNK_WRITE() methods in your code so you could restore all GPIO states.

Usage example - https://github.com/blynkkk/blynk-library/blob/master/examples/More/Sync/Sync.ino

Eah. I mean last value not the default one

Just one question
For example i set a default state of gpio in code

pinMode(16, OUTPUT);
digitalWrite(16, HIGH)

but after ESP was loaded i turned it to LOW via smartphone
and go far far away)))

Here comes an power loss.
So if i write
BLYNK_CONNECTED() {
if (isFirstConnect) {
Blynk.syncAll();
}
}

in code,
the default value(high) will be overwriten with low(cames previously from smartphone)?

It works THANK YOU!
Anyway im also interesting in ablity to send something to esp from cron or commandline)))

The simplest way would be to use HTTP API as you can do it directly from command line without any other dependencies with single CURL. http://docs.blynkapi.apiary.io/

Sorry but I got one more question
The sample here example
include only real pin read/write function.
But i need to change state of virutal pin V1 for example

curl --include
–request PUT
–header “Content-Type: application/json”
–data-binary “[
“1”
]”
http://blynk-cloud.com/auth_token/pin/V1
last line will be correct?

Seems fine. Please hide your auth-token

Its not mine, its from sample one))))

1 Like

Eah((((
My apache did not allow PUT method for it.((((
Did you ever slove problem for blynkk server?
Ill try to fix it myself.

I think i should start new topic for it

What problem do you mean?

Dont worry. Every think is OK. I have just realised that default http port of Blynk server is not 80 but 8080)))))

Yes, 80 and 443 ports require root rights.