Close

Datacake integration: Seeing Squeak on a map

A project log for Squeak: GPS pet tracker

Squeak is a LoRaWAN GPS pet tracker with a very long battery life. It allows you to ask your pets to share their location

mihaicuciucmihai.cuciuc 11/20/2022 at 18:050 Comments

Datacake can be used to integrate and visualize IoT data. It's a paid service, but you get two devices for free. It readily integrates with The Things Network and you can easily have a web interface for the Squeak tracker.

After registering Squeak in the The Things Network application, define a webhook for bidirectional communication with Datacake.

Use a custom payload decoder for Datacake to make sense of what's being sent

function Decoder(payload, port) {
    var decoded = {};

    decoded.counter =  (payload[1] << 8) | payload[2];
    decoded.battery = payload[3];
    decoded.temperature = payload[4];
	
    gpsYy = payload[5] >> 1;
    gpsMo = ((payload[5] & 0x01) << 3) | ((payload[6] & 0xE0) >> 5);
    gpsDd = payload[6] & 0x1F;
    gpsHh = (payload[7] & 0xF8) >> 3;
    gpsMi = ((payload[7] & 0x07) << 3) | ((payload[8] & 0xE0) >> 5);
	
    lat = ((payload[9] << 24) | (payload[10] << 16) | (payload[11] << 8) | payload[12]);
    lng = ((payload[13] << 24) | (payload[14] << 16) | (payload[15] << 8) | payload[16]);

    gpsTs = 0;
    gpsLat = -1000;
    gpsLon = -1000;
    
    if ((lat > -500) && (lng > -500))
    {
        ts = new Date(2000 + gpsYy, gpsMo - 1, gpsDd, gpsHh, gpsMi, 0, 0);
        //console.log(ts.getTimezoneOffset());  // Maybe one needs to adjust for timezones here. For now it looks like Datacake runs on the UTC timezone which is great.
        
        gpsTs = ts.getTime() / 1000;
        
        gpsLatF = lat / 10000000.0;
        gpsLatDD = ~~gpsLatF;
        gpsLatMM = (gpsLatF - gpsLatDD) * 100.0/60.0;
        gpsLat = gpsLatDD + gpsLatMM;
    
        gpsLonF = lng / 10000000.0;
        gpsLonDD = ~~gpsLonF;
        gpsLonMM = (gpsLonF - gpsLonDD) * 100.0/60.0;
        gpsLon = gpsLonDD + gpsLonMM;
    }

    decoded.timestamp = gpsTs;
    decoded.location = "(" + gpsLat + "," + gpsLon + ")";

    return decoded;
}

Add fields for the values you're interested in from the decoded structure. Things like battery, location, etc. Also add a downlink configuration to be able to send a command to turn on the GPS.

function Encoder(measurements, port) {
    return [0x02, 0x01, 0x03];
}

This payload says it should try to send an uplink every 4 minutes, and the GPS should be on for the following 3 packets. A UI is fairly easy to build up once you have the decoder, fields, and encoder set up.

Discussions