Ask us anything here
https://www.thethingsnetwork.org/marketplace/product/squid-sensor
1 Like
Hi there,
I was wondering if you had a decoder to translate the Ewattch Squid raw payload into usable JSON format?
Thank you
Dylan
do you search something like this?
function Decoder(bytes, port) {
// Decode an uplink message from a buffer
// (array) of bytes to an object of fields.
var decoded = {};
var frame_type= bytes[0] ;
var payload_size= bytes[1];
var channel= [0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000];
var object_type = bytes[2];
if (object_type === 0x48) decoded.object_type= "SQUID";
if (object_type === 0x00) decoded.object_type= "Environnement";
if (object_type === 0x01) decoded.object_type= "Presence";
if (object_type === 0x02) decoded.object_type= "Ambience";
if (object_type === 0x10) decoded.object_type= "Pulse";
if (object_type === 0x20) decoded.object_type= "TyNess";
if (frame_type === 0x00) //Data sent periodically
{
decoded.frame_type= "Data sent periodically";
var emplacement_byte= 5;
for (var num_pince=1; num_pince<=12; num_pince++) {
channel[num_pince]= bytes[emplacement_byte--] << 16 |bytes[emplacement_byte--] << 8 |bytes[emplacement_byte];
channel[num_pince]=channel[num_pince]/100000;
emplacement_byte += 5;
}
decoded.channel_1=channel[1];
decoded.channel_2=channel[2];
decoded.channel_3=channel[3];
decoded.channel_4=channel[4];
decoded.channel_5=channel[5];
decoded.channel_6=channel[6];
decoded.channel_7=channel[7];
decoded.channel_8=channel[8];
decoded.channel_9=channel[9];
decoded.channel_10=channel[10];
decoded.channel_11=channel[11];
decoded.channel_12=channel[12];
}
if (frame_type === 0x01) // data sent during an event
{
decoded.frame_type= "data sent during an event";
}
if (frame_type === 0x10) // Sensor status data
{
decoded.frame_type= "Sensor status data";
var firmware_version= {
major:bytes[6],
minor:bytes[5]
};
decoded.firmware_version= firmware_version;
var battery_level= bytes[8] ;
if (battery_level === 0x08) decoded.battery_level= "Mains power 80%";
if (battery_level === 0x07) decoded.battery_level= "Mains power 70%";
if (battery_level === 0x06) decoded.battery_level= "Mains power 60%";
if (battery_level === 0x05) decoded.battery_level= "Mains power 50%";
if (battery_level === 0x04) decoded.battery_level= "Middle level 40%";
if (battery_level === 0x03) decoded.battery_level= "Middle level 30%";
if (battery_level === 0x02) decoded.battery_level= "Middle level 20%";
if (battery_level === 0x01) decoded.battery_level= "Level Low 10%";
if (battery_level === 0x00) decoded.battery_level= "Level critical";
var periodicity = bytes[11] << 8 |bytes[10];
periodicity=periodicity*10;
decoded.periodicity= periodicity;
}
decoded.payload_size= payload_size;
return decoded;
}
1 Like
Thanks for sharing the decoder and the documentation!
Just as an aside, in JavaScript one can also use object['attributeName']
instead of object.attributeName
. With that, the following would achieve the same for the part that decodes the channel values, without the need for the temporary channel
array:
var i = 3;
for (var c = 1; c <= 12; c++) {
decoded['channel_' + c] =
(bytes[i++] | bytes[i++] << 8 | bytes[i++] << 16) / 100000;
}
1 Like
Hello, sorry for my newbie question. Does this thing measure active and reactive components of electrical power? Thanks