Missing variables on the Cloud

Hi Makers,
I hope you are doing well in your projects,
I think i’m mistaking something here with my code when i try to send some variables to the cloud
Would please help me about that,it is neither displaying the address in the console or publishing it as a variable.

Here’s my entire code :

    // This #include statement was automatically added by the Particle IDE.
    #include <OneWire.h>
    #include <Particle.h>

    void updateHexData(byte *data, size_t dataLength);

    String sensorData;
    String sensorAdd1;
    String sensorAdd2;
    String sensorAdd3;
    String sensorAdd4;

    OneWire wire = OneWire(D1);  // 1-wire signal on pin D4

    unsigned long lastUpdate = 0;

    void setup() {

    // Every 3 seconwire check for the next address on the bus
    // The scan resets when no more addresses are available

    void loop() {
    	int counter=0;
       unsigned long now = millis();
      // change the 3000(ms) to change the operation frequency
      // better yet, make it a variable!
      if ((now - lastUpdate) < 3000) {
      lastUpdate = now;
      byte addr[8];

      if (!wire.search(addr)) {
        Serial.println("No more addresses.");


      // Show the CRC status
      // you should always do this on scanned addresses
      if (OneWire::crc8(addr, 7) != addr[7]) {
          Serial.println("CRC is not valid!");
    updateHexData(addr, sizeof(addr));
    Particle.variable("FirstDevAdd", &sensorAdd1, STRING);
    Particle.publish("AddressesDS", "NewAddrDetected", 60, PUBLIC);
    else if(counter==2)
    updateHexData(addr, sizeof(addr));
    Particle.variable("SecondDevAdd", &sensorAdd2, STRING);
    Particle.publish("AddressesDS", "NewAddrDetected", 60, PUBLIC);
    else if(counter==3)
    updateHexData(addr, sizeof(addr));
    Particle.variable("ThirdDevAdd", &sensorAdd3, STRING);
    Particle.publish("AddressesDS", "NewAddrDetected", 60, PUBLIC);
    else if(counter==4)
    updateHexData(addr, sizeof(addr));
    Particle.variable("ForthDevAdd", &sensorAdd4, STRING);
    Particle.publish("AddressesDS", "NewAddrDetected", 60, PUBLIC);
    {Serial.println("There's another addresses.");}// You can add them though if statements

      wire.reset(); // clear bus for next use

    void updateHexData(byte *data, size_t dataLength) {
    	// Reserve buffer space so we only need to do one memory allocation when appending to sensorData
    	// Note that Particle.variable has a limit of 622 bytes, so the maximum dataLength is 310 or so bytes.
    	sensorData.reserve(dataLength * 2 + 1);

    	// This is where we store the one byte of hex data (two bytes of ASCII 0-9 and a-f).
    	char hexBuf[4];

    	// Convert the input data to hex
    	for(size_t ii = 0; ii < dataLength; ii++) {
    		snprintf(hexBuf, sizeof(hexBuf), "%02x", data[ii]);
    		if (ii == 0) {
    			sensorData = hexBuf;
    		else {
    			sensorData += hexBuf;

@mohammed, I suggest you revisit the documentation for Particle.variable(). The format you are using is deprecated. Also, the Particle.variable() declaration is done ONCE in setup(). :wink:


Thanks a lot Sir,

1 Like

Thanks for the help!