Requesting the state of a PB widget from code on the controller

I have two PBs. The PB assigned to V14 is the PB state that i am trying to monitor even when the hardware goes offline. V14 is also assigned to the LED widget. I am using the PB associated to V11 to request the state of the V14 and display it on the serial monitor

What about this?:

#include <BlynkSimpleSerialBLE.h>
char auth[] = "auth token";           //Auth token
int SDOption;

SYSTEM_MODE(MANUAL);                                        //Switches off the wifi module on photon on start up

WidgetLED myLed(V14);
int ledState;

BlynkTimer timer1;
int Powersave = 0;
void AllFunctions(void);

void setup()
{
  // Debug console
  Serial.begin(9600);
  Serial1.begin(9600);                                    //Initialise serial communication on the TX and RX pins
  pinMode(D7, OUTPUT);
  pinMode(A7, INPUT_PULLDOWN);
  Blynk.begin(Serial1, auth);
  Serial.println("Photon Setup completed");
  Blynk.notify("Hardware Online");
  delay(1000);
  timer1.setInterval(3000L, AllFunctions);
}



void loop()
{
  Blynk.run();
  timer1.run();
}

void AllFunctions() {
  ledState = myLed.getValue();
  Serial.printlnf("ledState: %i", ledState);
  if (ledState < 0) {
    Serial.println("The SD card will be on because the LED is ON");
  }
  if (digitalRead(A7) == LOW) {
    Powersave = 1;
    Serial.println("A7 is low");
    if (Powersave == 1) {
      Serial.println("Powersave mode activated");
      System.sleep(A7, RISING, 2);
    }
  } else {
    Powersave = 0;
  }
}


BLYNK_WRITE(V14) {
  SDOption = param.asInt();
  if (SDOption < 0) {
    Serial.println("PB is ON");
  } else {
    Serial.printlnf("PB is OFF");
  }
}

BLYNK_WRITE(V11) {
  int pinData = param.asInt();

  if (pinData == HIGH) {
    digitalWrite(D7, HIGH);
    Serial.println("LED is ON");
    //Blynk.syncVirtual(V14);
    Serial.printlnf("Virtual pin V14: %d", SDOption);
  } else {
    digitalWrite(D7, LOW);
    Serial.println("LED is OFF");
  }
}

Perhaps I am the only one, but I do not understand the exact nature of your desired task… if the device is offline/sleeping, then your code is not running (at lease not with a Blynk connection) thus you can not monitor anything.

Ah okay i think i understand your confusion. I am sorry i also forgot to mention that the PB assigned to V11 was used to switch on an LED on my hardware, as a means of verifying that i have a connection between my app and hardware, and i just used this for a double purpose of also indicating the state of the LED widget. You will see i defined D7 as an output which is the pin associated with the hardware LED. Is this what you question was referring to?

What i mean is that i would like my hardware to be able to determine the state of the PB after it returns from sleep so that it does not miss the change in state completely

Normaly that is handled with a Blynk.syncVirtual(vPin) command… but that is not an option with BT/BLE… you are simply trying to do things that were not meant to be done with that connection type.

Sorry I didn’t say - I changed some of your code slightly, changed the == 255 to < 0 to see if that made a difference?

@Gunner
I have tried this function in this manner but it does not work. Is there another way that this function might be implemented?

NOT with BT/BLE… perhaps in Blynk 2.0 the Devs may work that connection method differently to allow full Server link passthrough support, but apparently not yet.

i am not sure i understand. This means this command will execute when the push button is not pressed:

Serial.println(“The SD card will be on because the LED is ON”);

Also the value returned by the ledState is constantly 0. I am not sure how this is suppose to help but i will give a try a little later on:confused:

I can see it is a real uphill climb. I wish i had realised this before but it is a little too late to change. :anguished:

Okay i hope so. Any idea when this might be:pray:

And why is changing to an ESP8266 or something an issue exactly??

Nope… I is just a volunteer Blynk user :slight_smile:

1 Like

My entire project is based on a Particle Photon. It would mean redesigning software and my entire circuit board close to my deadline. Also how would changing to an ESP8266 change the situation ?

oh okay. Thank you very much for volunteering your experience and expertise. And thank you to @PeteKnight @JustBertC. I am really grateful to have people to turn to for new ideas on resolving issues that i am stuck with. Thank you for willing to assisst :slightly_smiling_face::+1:

Maybe @BlynkAndroidDev can shed some light.

Is this a school project or commercial prototype?? (since actual commercial use is verboten with this development side of Blynk) Either way there should be allowance for some redesign.

An ESP8266 like a NodeMCU or Wemos D1 Mini is a complete WiFi enabled IoT development device and would allow FULL Blynk commands, syncing after sleep, running without App link or even Server link, etc, etc.

College project.

The Photon is also a WiFi enabled IoT developement device but the design requirement is to use Bluetooth communication. And i think this is where the problem lies.

Then you simply have to work within the limitations of that type of link… or find a workaround to incorporate it in some other way… perhaps using the BT link to some other device/App while using the WiFi with Blynk? I guess it depends on exactly what the course criteria of the BT link is

I am not sure how that will work but if there are no other simpler work-around i would have to investigate this. Although i am not sure why some of these commands like the sync commands don’t actually work with BT/BLE since, as you said, the App is the link between the Server and the hardware. But i guess this is something for the developers to comment on.

Probably because BT/BLE was an early connection option for Arduino boards at the beginning of Blynk… just like USB link for Arduino (although that actually supports a FULL Server link :stuck_out_tongue_winking_eye: ). The ESP8266 was relatively new and early Blynk development may not even have gotten to things like Sync yet… That was all a bit before my time starting with Blynk.

Now the developers are pursuing the commercial side and this up and coming Blynk 2.0 (whatever exactly that is :stuck_out_tongue: ) and probably not all that willing to devote time and resources to “fix” the old tech with the new features… yet.

I would think it would be in their interest to work on BT/BLE connection features since the momentum of industry seems to be moving towards Bluetooth mesh technology. Whatever the case is. only time will tell.
Thank you @Gunner @PeteKnight @JustBertC for your time, assistance and advice. If i am able to think of another work around i will post here. If anyone thinks of a work-around please also post here. Till then, its back to the drawing board for me :frowning_face:.