Ubidots Community

Can a "dot" coming in from a Lorawan TTS server be a text value

My TTN open source server is sending dots via the HTTP integration.

However, one of the dots is “status”: “OPEN” (or close).

It isn’t a number.

Ubidots did not recognize it and I did not see a way to change the variable to text.

Do I always need to send over a numeric value? Or can a text value be received (if so, how)

Thx,
Marlan

Hello Marlan,
Thank you for reaching out to our Community Forum.

No, our API does not support text as variable values. It can support numbers in the form of a string, but not text itself. Nonetheless, the Context field of a Dot does support Text, so if you want to send an OPEN or CLOSE, then you’ll have to include that in the Context of the Dot being sent. For more information on this, please view this arcticle.

On to how it can be done, in this case, you can use the Decoder (or Payload Format) to change the format of the payload being sent to Ubidots. Also, you should map the OPEN or CLOSED to 1 or 0, respectively.

Please let us know if you have any questions.

Best regards,
Sebastián

Hello, @marlanw

I hope you’re well and thank you for reaching out.

You can send strings as part of an Ubidots dot inside a context object, for example:

{
   "value":1,
   "context":{
      "state":"open"
   }
}

Regarding the integration with the TTS network server, you can modify the decoder for your device in a way that its payload contains a dot for the variable of interest for example this decoder:

function Decoder (bytes, port) {
  var decoded = {}

  for (var i = 0; i < bytes.length; ) {
    var channel_id = bytes[i++]
    var channel_type = bytes[i++]
    // BATTERY
    if (channel_id === 0x01 && channel_type === 0x75) {
      decoded.battery = bytes[i]
      i += 1
    }
    // PIR
    else if (channel_id === 0x03 && channel_type === 0x00) {
      decoded.pir = bytes[i] === 0 ? {'value':0, context:{'state':'normal'}} : {'value':1, context:{'state':'trigger'}};
      i += 1
    }
    // DAYLIGHT
    else if (channel_id === 0x04 && channel_type === 0x00) {
      decoded.daylight = bytes[i] === 0 ? {'value':0, context:{'state':'dark'}} : {'value':1, context:{'state':'light'}};
      i += 1
    } else {
      break
    }
  }

  return decoded
}

Originally, the decoding part of the PIR section suggested by the manufacturer was like this.

decoded.pir = bytes[i] === 0 ? 'normal' : 'trigger';

but then it was updated to this, In order to show that “state” inside a context:

decoded.pir = bytes[i] === 0 ? {'value':0, context:{'state':'normal'}} : {'value':1, context:{'state':'trigger'}};

Does this make sense?

I’ll be attentive to your comments.

Regards,

-Santiago

Perfect!!!