If you decode your try:
GET / HTTP/1.1 Connection: Keep-Alive Accept-Encoding: gzip, deflate Accept-Language: en-US,* User-Agent: Mozilla/5.0 Host: kiryat8.com:5055
As you can see, there is no data.
OK here is the code which I tried a POST now:
function request() {
var sF = [
"id=",
"?timestamp=",
"?lat=",
"?lon=",
"?speed=",
"?bearing=",
"?altitude=",
"?batt="
];
var xhr = new XMLHttpRequest();
var url = "http://kiryat8.com:5055";
var str = sF[0] + tracReading.deviceid
str = str + sF[1] + tracReading.timestamp
str = str + sF[2] + tracReading.lat
str = str + sF[3] + tracReading.lon
str = str + sF[4] + tracReading.speed
str = str + sF[5] + tracReading.bearing
str = str + sF[6] + tracReading.altitude
str = str + sF[7] + tracReading.battery
// data in Hex string format
var params = toHex(str);
xhr.open("POST", url, true);
// Send the proper header information along with the request
//xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");
xhr.setRequestHeader('Content-Type', 'text/plain; charset=utf-8');
xhr.setRequestHeader("Content-length", params.length);
// xhr.setRequestHeader("Content-Encoding", "gzip");
// xhr.setRequestHeader("Connection", "close");
xhr.setRequestHeader('User-Agent', 'HTTP/1.1');
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
print('HEADERS_RECEIVED')
} else if(xhr.readyState === XMLHttpRequest.DONE) {
print('DONE')
// var json = JSON.parse(xhr.responseText.toString())
// view.model = json.items
}
}
xhr.send(params);
}
Here is the log:
2016-09-28 11:37:17 INFO: [5085D166] connected
2016-09-28 11:37:17 DEBUG: [5085D166: 50055 < 37.26.149.183] HEX: 504f5354202f20485454502f312e310d0a436f6e74656e742d547970653a20746578742f706c61696e3b20636861727365743d5554462d380d0a436f6e74656e742d4c656e6774683a203232360d0a436f6e6e656374696f6e3a204b6565702d416c6976650d0a4163636570742d456e636f64696e673a20677a69702c206465666c6174650d0a4163636570742d4c616e67756167653a20656e2d55532c2a0d0a557365722d4167656e743a204d6f7a696c6c612f352e300d0a486f73743a206b6972796174382e636f6d3a353035350d0a0d0a
2016-09-28 11:37:17 DEBUG: [5085D166: 50055 < 37.26.149.183] HEX: 36393634336433333337333433343338333333663734363936643635373337343631366437303364333133343336333833353337333633373333333633663663363137343364333333353265333533373334333033353332333233353330333033313332333733353335336636633666366533643333333332653332333133393339333933353334333933383336333533373332333233663733373036353635363433643330336636323635363137323639366536373364333033663631366337343639373437353634363533643330336636323631373437343364333133303330
2016-09-28 11:37:17 DEBUG: [5085D166: 50055 > 37.26.149.183] HEX: 485454502f312e31203430302042616420526571756573740d0a436f6e74656e742d4c656e6774683a20300d0a0d0a
Have you actually tried to decode what Traccar Client sends and compare it to what your code sends? Parameters should go into the URL, not content of the message. Also, why are you encoding data into HEX format?
Thanks a million!
I switched to Android and to my nginx server and checked the log.
I will do the same on Ubuntu phone and see where I went wrong.
I did look on Google but there is a learning curve.
Will let you know
You can decode HEX data here if you need:
OK I got it working after fixing formating errors and you pointed out that the data should be appended to the URL and not in the send.
I will continue to play around trying to add settings and seeing if it is possible to wake up at a given interval in Ubuntu phone to send the data.
Thanks
function request() {
var sF = [
"?id=",
"×tamp=",
"&lat=",
"&lon=",
"&speed=",
"&bearing=",
"&altitude=",
"&batt="
];
var xhr = new XMLHttpRequest();
var url = "http://kiryat8.com:5055";
var str = sF[0] + tracReading.deviceid
str = str + sF[1] + tracReading.timestamp
str = str + sF[2] + tracReading.lat
str = str + sF[3] + tracReading.lon
str = str + sF[4] + tracReading.speed
str = str + sF[5] + tracReading.bearing
str = str + sF[6] + tracReading.altitude
str = str + sF[7] + tracReading.battery + " HTTP/1.1 200 "
var params = str + str.length + " ";
xhr.open("GET", url+params, true);
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
print('HEADERS_RECEIVED')
} else if(xhr.readyState === XMLHttpRequest.DONE) {
print('DONE')
}
}
// Send with data appended to URL
xhr.send();
}
Thanks for sharing the code by the way. It might be useful for others some day.
I have an older Nexus4 phone which I dual boot Android & Ubuntu touch.
Do you have an Ubuntu phone client? I was playing around with the Ubuntu SDK and created a primitive client which gets the location every interval and can send the data to my home web server when a button is clicked. I use the OsmAnd protocol I guess looking at your Android ProtocolFormatter java code. I am not a QML or JavaScript programmer (real-time C programmer) but have created several Android utilities mainly for myself when needed. I tried using the XMLHttpRequest class to send the data but the server does not parse my ill formed message evidently.
Since you evidently know Java & JavaScript well maybe you can send me a snippet on how to send the reading. Thanks
This is one of my tries:
This is my son's phone which is recognized of course from the Android client: