BLYNK
BLYNK.IO       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Converting from bridge to HTTP API data

Trying to understand how to move from using bridge data to the http API data

I use bridge data to authorize NFC cards at various doors in my lock project

/*
   this will copy data to the device with the id sent as param[1]
   param[0] determines if we copy all data or just 1 card
*/
BLYNK_WRITE(bridgewrite)
{
  String stoken = param[1].asStr();   // get the lock token string
  char token[BLYNKSIZE];
  byte tokenbytes[BLYNKSIZE];

  stoken.getBytes(tokenbytes, BLYNKSIZE);    // copy the token string to a char array
  for ( int i = 0; i < BLYNKSIZE; i++) {
    token[i] = tokenbytes[i];
  }

  bridge_lock.setAuthToken(token);    // set the bridge token to the lock

  bridge_lock.virtualWrite(bridgedata, cardHolder[0], cardId[0], accessFlags[0]);     //copy current card from reader

}

/*
   this will copy data to the device with the id sent as param[1]
   param[0] determines if we copy all data or just 1 card
*/
BLYNK_WRITE(bridgewriteall)
{
  String stoken = param[1].asStr();   // get the lock token string
  char token[BLYNKSIZE];
  byte tokenbytes[BLYNKSIZE];

  stoken.getBytes(tokenbytes, BLYNKSIZE);    // copy the token string to a char array
  for ( int i = 0; i < BLYNKSIZE; i++) {
    token[i] = tokenbytes[i];
  }

  bridge_lock.setAuthToken(token);    // set the bridge token to the lock

  for (int i = 1; i <= rowIndex; i++) {
    bridge_lock.virtualWrite(bridgedata, cardHolder[i], cardId[i], accessFlags[i]);    //copy all cards from reader
    yield();
  }
}


BLYNK_WRITE(copybutton)
{
  if (param.asInt()) {
    bridge_master.virtualWrite(bridgewrite, 1, lock_token);         //tell masterlock to copy current card to current lock
  }
}

I think that you can now use Automations (although I’ve not tried it myself).
If you want to use the API then you should probably read this…

Pete.

You can use the automation as switch only ( on/off ) based on certain trigger, you can’t send data like sensors data between devices using automation.
If you would like to send data between devices then you can check the topic suggested by pete, or you can try Node-red.

1 Like