Tracker and PublishQueuePosixRK

Has anyone played around with getting the Tracker Edge firmware working with the PublishQueuePosixRK library for offline caching? I’d love not to have to start from scratch with tracker firmware because the edge provides so much functionality build in.

The library works if you install it as a library with the Tracker Edge source. The problem is that you can’t just replace the location publish with a queued publish. It requires a more complex change to the CloudService in Tracker Edge.

I’ve been working on this but it seems to be throwing out all my files as ‘corrupted’.

Setup is essentially this:

// PosixQueue variables
const int ramQueueSize = 0;
const int fileQueueSize = 100;
const char * fileDirPath = "/publishQueue";
bool publishReady = false;
char publishBuffer[900];

void setup()
{
    PublishQueuePosix::instance().setup();
    PublishQueuePosix::instance().withRamQueueSize(ramQueueSize);
    PublishQueuePosix::instance().withFileQueueSize(fileQueueSize);
    PublishQueuePosix::instance().withDirPath(fileDirPath);
    // Start Tracker
    Tracker::instance().init();
}

loop:

void loop()
{
    // Update Tracker
    PublishQueuePosix::instance().loop();
    Tracker::instance().loop();
Log.info("Got to custom location Publish");
    // Create JSONBufferWriter
    memset(publishBuffer, 0, sizeof(publishBuffer));
    JSONBufferWriter writer(publishBuffer, sizeof(publishBuffer)-1);
    writer.beginObject();

    int bits = tls.GetBits();
    writer.name("time").value(Time.now());
    writer.name("bits").value(bits);

    // Add voltage value of sensor to location payload
    double voltage = tls.GetVoltage();
    writer.name("volt").value(voltage, 2);
    
    // Add calculated inches value from sensor to location payload
    double inches = tls.GetInches();
    writer.name("inches").value(inches, 2);

    // Add calculated barrels value from sensor to location payload
    double barrels = tls.GetBarrels();
    writer.name("barrels").value(barrels, 2);

    // Add boolean flags for dispense and filling to location payload
    writer.name("isSensorFailing").value(tls.IsSensorFailing());

    // Get Location Point and Write
    LocationPoint point = {};
    
    if(Tracker::instance().locationService.getLocation(point) != SYSTEM_ERROR_NONE){
        writer.name("lck").value(point.locked);
        writer.name("lat").value(point.latitude);
        writer.name("lon").value(point.longitude);
        writer.name("alt").value(point.altitude);
        writer.name("spd").value(point.speed);
        // Add isMoving flag to location payload
        bool isMoving = point.speed > isMovingThreshold;
        writer.name("isMoving").value(isMoving);
    } else {
        writer.name("lck").value(0);
    }

    // Get Cell Data and Write
    CellularSignal signal;
    if(!TrackerCellular::instance().getSignal(signal))
    {
        writer.name("cell").value(signal.getStrength(), 1);
    }

    // Get Battery Data and Write
    int bat_state = System.batteryState();
    writer.name("battState").value(bat_state);
    if(bat_state == BATTERY_STATE_NOT_CHARGING || bat_state == BATTERY_STATE_CHARGING ||bat_state == BATTERY_STATE_DISCHARGING || bat_state == BATTERY_STATE_CHARGED)
    {
        float bat = System.batteryCharge();
        if(bat >= 0 && bat <= 100)
        {
            writer.name("batt").value(bat, 1);
        }
    }
    writer.endObject();
    PublishQueuePosix::instance().publish("cLoc",publishBuffer,PRIVATE,WITH_ACK);
}

Logs:

0000329434 [app.pubq] TRACE: writeQueueToFiles fileNum=9
0000329434 [app.seqfile] TRACE: getFileFromQueue returned 9
0000329436 [app.pubq] TRACE: fileNum=9 size=536898020
0000329436 [app.pubq] TRACE: readQueueFile 9 bad magic=00000000 version=64 headerSize=98 nameLen=8193
0000329437 [app.pubq] INFO: discarding corrupted file 9
0000329438 [app.seqfile] TRACE: getFileFromQueue returned 9
0000329439 [app.seqfile] TRACE: removed /publishQueue/00000009

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.