Device attributes won't save to DB

Bogdan Matei3 years ago

Hello,
I am trying to implement a custom protocol in traccar and I am stuck at this problem:

  • my implementation require that I can set device attributes :
    device.set("nextTemp",nextTemp);

The problem is that the device attributes are not updated in database. The attributes field in the DB remain {} even if the device.getAttributes().toString() return all the attributes added in the java code.

Please help to save or force save the attributes to DB for devices.

Thank you !

Bogdan Matei3 years ago

I think I found the answer myself :

Context.getDeviceManager().updateItem(device);

Please someone with more experience confirm/infirm this .

Thank you !

Anton Tananaev3 years ago

Looks correct.

Pata year ago

How can we do this in the latest code base? There is no global like "Context" which can be accessed from decoder. This is where we want to update some property of device and store it in database. How can we do it now?

Anton Tananaeva year ago

We use injection instead of global context now.