[SOLVED] Dev_name to replace VARIABLE_LABEL

Hi There.

I have 3 Particle Xenons and 1 Argon. The 3 Xenons are sending their battery to the Ubidot dashboard every time a timer expires. When the timer is called voltage i sent as follow

#ifdef Xenon
      
 void timerUbidotInformation(void){
  
   float voltage = analogRead(BATT) * 0.0011224;
   Particle.publish("voltage", String::format("%.2f",voltage), PRIVATE);
   Particle.subscribe("particle/device/name", Name_of_Device);  // get the device name   
   Particle.publish("particle/device/name");  // ask the cloud for the name to be sent to you
   ubidots.add(dev_name, voltage);
   ubidots.meshPublishToUbidots("Ubidots"); // webhook its publishing to on particle consol
 }
#endif

This seems to only work after the 2nd time the function is called. On the first time it seems to publish the battery voltage as a label with “0” data.

Any bettter way to do it.
image

Hello @Melt777,

I suspect the error is being generated by some gateway configurations. Could you share the code you are using in the Argon? This way I can evaluate the actual configurations, and check if they are the cause of the problem.

Cheers,
Maria H.

Hi there, which protocol are you using in your gateway? If you use HTTP or TCP, they have implemented a throttling of 20 seconds in the gateway side to avoid memory issues, so I suspect that some of the data of your nodes is being rejected because of this. My advise for two or more nodes is to use UBI_PARTICLE as iot protocol in your gateway, in this way you will use particle webhooks and won’t be affected by the library’s throttling.

All the best

Thanks Guys, I am using Ubidots ubidots(“webhook”, UBI_PARTICLE); on both Argon and Xenon.I removed 2 xenons and only have one connected so that I can see whats happening.
It looks like a timing issue between the Mesh.ready() and the request of dev_name, Not much code on my Argon that would influence this except in the setup.

I am now experimenting with " waitUntil(Particle.connected); " as I suspect im requesting the name to be returned before its connected.

   #define Argon // all below is for argon gateway

   int led2 = D7;
   bool DetonateSatus = 0; // holds the status for detonation.
  SYSTEM_THREAD(ENABLED);
  const char *EVENT_NAME = "Beacon MAC"; // here we need to change it to name of node if possible
  /********************************************************************************************/
  //Ubidots
 const char* WEBHOOK_NAME = "Ubidots";
 Ubidots ubidots("webhook", UBI_PARTICLE);
 //Ubidots ubidots(UBIDOTS_TOKEN, UBI_INDUSTRIAL, UBI_MESH);

    void setup() {

SYSTEM_MODE(AUTOMATIC);
Particle.keepAlive(20);
Serial.begin(115200);
pinMode(led2, OUTPUT); // output for triggered led
BLE.setTxPower(-8); // Use lower power // Use lower power -20, -16, -12, -8, -4, 0, 4, 8.
timer.start(); // start timer to send info to ubidots once per hour or whatever its set to
//ubidots.setDebug(true);  // Uncomment this line for printing debug messages
ubidots.setCloudProtocol(UBI_PARTICLE);
softDelay(5000); // Allow board to settle
 }

That probably may be the issue, would you mind to uncomment the setDebug() and to print what do you get in your serial monitor for both node and gateway?

I will be attentive

Adding “ubidots.setDebug(true);” in my Xenon setup for some reason does not print out any debug or payload info. What I did was inserted some Serial.printlnf statements at each step to see when the name is copied. my findings and my solution below.

    //when timer expires  send battery voltage with Xenon name.
 void timerUbidotInformation(void){

     float voltage = analogRead(BATT) * 0.0011224;
     Particle.publish("voltage", String::format("%.2f",voltage), PRIVATE);
    // get the device name    
    waitUntil(Particle.connected);
    Particle.subscribe("particle/device/name", Name_of_Device);
    softDelay(3000);
    Particle.publish("particle/device/name");  // ask the cloud for the name to be sent to you
    ubidots.add(dev_name, voltage); //pair Vbatt with name of Xenon
   ubidots.meshPublishToUbidots("Ubidots"); // webhook its publishing to on particle console
  }

// used for getting the device name ***********************************************
void Name_of_Device(const char *topic, const char *data) {
  strncpy(dev_name, data, sizeof(dev_name)-1);
  Serial.printlnf("received name from subscribe/publish call : %s", dev_name);
  publishName = true;
  strncpy(VARIABLE_LABEL, dev_name, sizeof(dev_name));
  Serial.printlnf("variable label %s", VARIABLE_LABEL);

}

the above results in

The following seems to work.

//when timer expires  send battery voltage with Xenon name.
void timerUbidotInformation(void){
  waitUntil(Particle.connected);
  Particle.subscribe("particle/device/name", Name_of_Device);
  softDelay(3000);
  Particle.publish("particle/device/name");  // ask the cloud for the name to be sent to you
 }

// used for getting the device name ***********************************************
void Name_of_Device(const char *topic, const char *data) {
  strncpy(dev_name, data, sizeof(dev_name)-1);
  Serial.printlnf("received in supscribe/publish request%s: %s", topic, dev_name);
  publishName = true;
  strncpy(VARIABLE_LABEL, dev_name, sizeof(dev_name));
  Serial.printlnf("variable label  that is copied from dev_name : %s", VARIABLE_LABEL);
  float voltage = analogRead(BATT) * 0.0011224;
  Particle.publish("voltage", String::format("%.2f",voltage), PRIVATE);
  ubidots.add(VARIABLE_LABEL, voltage); //pair Vbatt with name of Xenon
  Serial.printlnf("variable label that is uploaded to ubidots :  %s", VARIABLE_LABEL);
  ubidots.meshPublishToUbidots("Ubidots"); // webhook its publishing to on particle consol

}
timer%202

Order is now different.

Hi there @Melt777, thanks for sharing your solution, my thoughts are related with the variable dev_name , probably there is a type issue (the add() method expect a const char* type) or that array is not being populated as fast as you need.

Anyway, I am glad to know that it is working properly at your side.