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

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:.

That is a somewhat different development than the current PAN point to point use, so even if they are looking that way, it will likely not be in time for your needs :wink:

Sorry @Alli,

I put my greater than signs the wrong way :crazy_face:

Corrected:

#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");
  }
}

That is less than adequate performance :laughing:

2 Likes

After further testing of the Blynk.connected() and the BLYNK_CONNECTED(), i realized that when my hardware is put in sleep mode its connection to the blynk server is NOT lost because the BLYNK_CONNECTED() does not execute. This function only executes after the connection of my hardware to the Blynk server is lost and when it is restored then i.e. this function only executes when i disconnect the bluetooth connection between the app and the hardware and reconnect it or when i close the blynk app and re-open it. Since this is the case i will not be able to use this method to check the state of the PB

The connection IS lost, but because the Device is sleeping, no code can run to check that fact and do something about it.

2 Likes