I have written a javascript function to register new devices to my Traccar server from my Cordova Phonegap application, shown below. This function successfully adds a new device to the server however the incoming data from the device does not update the device in Traccar. The device comes online and goes offline immediately.
In the logs I can see that an error occurs when data from the device is received and the server does not respond so then the connection with the device times out and disconnects. I have posted the log below the javascript function.
The devices I am using are EV-07 and Traccar client. When I add devices from the Traccar Web App interface everything works correctly, but when I remove the device and try add it from my app it does not update.
function RegisterDevice(){
let name = document.getElementById('add-device-name').value.toString();
let model = document.getElementById('add-device-model').value.toString();
let imei = document.getElementById('add-device-imei').value.toString();
let deviceData = {
id: null,
name: name,
uniqueId: imei,
status: null,
disabled: null,
lastUpdate: null,
positionId: null,
groupId: null,
phone: null,
model: model,
contact: null,
category: null,
geofenceIds: null,
attributes: null
};
$.ajax({
type: 'post',
url: 'http://' + serverIP + '/api/devices',
data: JSON.stringify(deviceData),
contentType: "application/json; charset=utf-8",
dataType: 'json',
xhrFields: {
withCredentials: true
},
headers: {
"Accept": "application/json"
},
success: function () {
console.log('added');
LoadHome();
AlertBanner('success', 'device');
},
error: function(exception){
HideLoading();
OpenPage('add');
AlertBanner('fail', 'device');
console.log(exception);
}
});
}
logs
2018-12-08 11:01:05 INFO: [9220bc77] connected
2018-12-08 11:01:05 INFO: [9220bc77: 5055 < 217.46.113.75] HEX: 504f5354202f3f69643d3437373939302674696d657374616d703d31353434323636383635266c61743d35322e3635373433373838266c6f6e3$
2018-12-08 11:01:05 INFO: [9220bc77: 5055 > 217.46.113.75] HEX: 485454502f312e3120323030204f4b0d0a636f6e74656e742d6c656e6774683a20300d0a0d0a
2018-12-08 11:01:05 WARN: [9220bc77] error - NullPointerException (DeviceManager:358 < *:347 < OverspeedEventHandler:115 < BaseEventHandler:27 < ...)
2018-12-08 11:01:05 INFO: [9220bc77] disconnected
2018-12-08 11:01:34 INFO: [312978f7] connected
2018-12-08 11:01:35 INFO: [ff99726a] connected
2018-12-08 11:01:35 INFO: [ff99726a: 5055 < 217.46.113.75] HEX: 504f5354202f3f69643d3437373939302674696d657374616d703d31353434323636383935266c61743d35322e3635373433373439266c6f6e3$
2018-12-08 11:01:35 INFO: [ff99726a: 5055 > 217.46.113.75] HEX: 485454502f312e3120323030204f4b0d0a636f6e74656e742d6c656e6774683a20300d0a0d0a
2018-12-08 11:01:35 WARN: [ff99726a] error - NullPointerException (DeviceManager:358 < *:347 < OverspeedEventHandler:115 < BaseEventHandler:27 < ...)
2018-12-08 11:01:35 INFO: [ff99726a] disconnected
2018-12-08 11:01:37 INFO: [312978f7: 5062 < 31.161.159.32] HEX: 21312c3836323634333033323832363034363b
2018-12-08 11:01:39 INFO: [312978f7: 5062 < 31.161.159.32] HEX: 21442c30382f31322f31382c31313a30313a33342c35322e3635373436332c2d302e3531323231302c302c3335302c3135303030312c37362e3$
2018-12-08 11:01:39 WARN: [312978f7] error - NullPointerException (ExtendedModel:96 < OverspeedEventHandler:124 < BaseEventHandler:27 < ...)
2018-12-08 11:01:39 INFO: [312978f7] disconnected
2018-12-08 11:02:05 INFO: [6051d738] connected
2018-12-08 11:02:05 INFO: [6051d738: 5055 < 217.46.113.75] HEX: 504f5354202f3f69643d3437373939302674696d657374616d703d31353434323636393235266c61743d35322e3635373433373234266c6f6e3$
2018-12-08 11:02:05 INFO: [6051d738: 5055 > 217.46.113.75] HEX: 485454502f312e3120323030204f4b0d0a636f6e74656e742d6c656e6774683a20300d0a0d0a
2018-12-08 11:02:05 WARN: [6051d738] error - NullPointerException (DeviceManager:358 < *:347 < OverspeedEventHandler:115 < BaseEventHandler:27 < ...)
2018-12-08 11:02:05 INFO: [6051d738] disconnected
2018-12-08 11:02:35 INFO: [34dd1231] connected
2018-12-08 11:02:35 INFO: [34dd1231: 5055 < 217.46.113.75] HEX: 504f5354202f3f69643d3437373939302674696d657374616d703d31353434323636393535266c61743d35322e3635373433373233266c6f6e3$
2018-12-08 11:02:35 INFO: [34dd1231: 5055 > 217.46.113.75] HEX: 485454502f312e3120323030204f4b0d0a636f6e74656e742d6c656e6774683a20300d0a0d0a
2018-12-08 11:02:35 WARN: [34dd1231] error - NullPointerException (DeviceManager:358 < *:347 < OverspeedEventHandler:115 < BaseEventHandler:27 < ...)
2018-12-08 11:02:35 INFO: [34dd1231] disconnected
2018-12-08 11:02:36 INFO: [350b28af] connected
2018-12-08 11:02:39 INFO: [350b28af: 5062 < 188.206.67.221] HEX: 21312c3836323634333033323832363034363b
2018-12-08 11:02:41 INFO: [350b28af: 5062 < 188.206.67.221] HEX: 21442c30382f31322f31382c31313a30323a33352c35322e3635373432352c2d302e3531323231302c312c3335302c3135303030312c37332e$
2018-12-08 11:02:41 WARN: [350b28af] error - NullPointerException (ExtendedModel:96 < OverspeedEventHandler:124 < BaseEventHandler:27 < ...)
2018-12-08 11:02:41 INFO: [350b28af] disconnected
2018-12-08 11:03:05 INFO: [b4838d54] connected
2018-12-08 11:03:05 INFO: [b4838d54: 5055 < 217.46.113.75] HEX: 504f5354202f3f69643d3437373939302674696d657374616d703d31353434323636393835266c61743d35322e3635373433373239266c6f6e3$
2018-12-08 11:03:05 INFO: [b4838d54: 5055 > 217.46.113.75] HEX: 485454502f312e3120323030204f4b0d0a636f6e74656e742d6c656e6774683a20300d0a0d0a
2018-12-08 11:03:05 WARN: [b4838d54] error - NullPointerException (DeviceManager:358 < *:347 < OverspeedEventHandler:115 < BaseEventHandler:27 < ...)
2018-12-08 11:03:05 INFO: [b4838d54] disconnected
2018-12-08 11:03:34 INFO: [55559eed] connected
2018-12-08 11:03:35 INFO: [a782c884] connected
2018-12-08 11:03:35 INFO: [a782c884: 5055 < 217.46.113.75] HEX: 504f5354202f3f69643d3437373939302674696d657374616d703d31353434323637303135266c61743d35322e3635373433373238266c6f6e3$
2018-12-08 11:03:35 INFO: [a782c884: 5055 > 217.46.113.75] HEX: 485454502f312e3120323030204f4b0d0a636f6e74656e742d6c656e6774683a20300d0a0d0a
2018-12-08 11:03:35 WARN: [a782c884] error - NullPointerException (DeviceManager:358 < *:347 < OverspeedEventHandler:115 < BaseEventHandler:27 < ...)
2018-12-08 11:03:35 INFO: [a782c884] disconnected
2018-12-08 11:03:37 INFO: [55559eed: 5062 < 31.161.186.202] HEX: 21312c3836323634333033323832363034363b
2018-12-08 11:03:39 INFO: [55559eed: 5062 < 31.161.186.202] HEX: 21442c30382f31322f31382c31313a30333a33342c35322e3635373433332c2d302e3531323135322c302c3335302c3135303030312c36372e$
2018-12-08 11:03:39 WARN: [55559eed] error - NullPointerException (ExtendedModel:96 < OverspeedEventHandler:124 < BaseEventHandler:27 < ...)
2018-12-08 11:03:39 INFO: [55559eed] disconnected
Have you check the post method info in the browser console when using Web application and compare it with yours?
Looks like you are missing attributes. Include empty JSON object.
Thank you Ernesto and Anton for your replies. As Anton advised I have replaced the null value for the attributes field with an empty JSON and now the device is updating it's attributes accordingly, Thank you for your help guys!
I have written a javascript function to register new devices to my Traccar server from my Cordova Phonegap application, shown below. This function successfully adds a new device to the server however the incoming data from the device does not update the device in Traccar. The device comes online and goes offline immediately.
In the logs I can see that an error occurs when data from the device is received and the server does not respond so then the connection with the device times out and disconnects. I have posted the log below the javascript function.
The devices I am using are EV-07 and Traccar client. When I add devices from the Traccar Web App interface everything works correctly, but when I remove the device and try add it from my app it does not update.
function RegisterDevice(){ let name = document.getElementById('add-device-name').value.toString(); let model = document.getElementById('add-device-model').value.toString(); let imei = document.getElementById('add-device-imei').value.toString(); let deviceData = { id: null, name: name, uniqueId: imei, status: null, disabled: null, lastUpdate: null, positionId: null, groupId: null, phone: null, model: model, contact: null, category: null, geofenceIds: null, attributes: null }; $.ajax({ type: 'post', url: 'http://' + serverIP + '/api/devices', data: JSON.stringify(deviceData), contentType: "application/json; charset=utf-8", dataType: 'json', xhrFields: { withCredentials: true }, headers: { "Accept": "application/json" }, success: function () { console.log('added'); LoadHome(); AlertBanner('success', 'device'); }, error: function(exception){ HideLoading(); OpenPage('add'); AlertBanner('fail', 'device'); console.log(exception); } }); }
logs