1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
// flag A
//IWAP01080524A2232.9806N11404.9355E000.1061830323.8706000908000102,460,0,9520,3671#
// flag else
//IWAP01080524V0000.0000N00000.0000E000.1061830323.8706000908000102,460,0,9520,3671,Home|74-DE-2B-44-88-8C|97&Home1|74-DE-2B-44-88-8C|97&Home2|74-DE-2B-44-88-8C|97&Home3|74-DE-2B-44-88-8C|97#
//
// ON S'AMUSE A PARTIR D'ICI
//
let answer = {}
let elements = msg.payload.split(",") // array containing the bits
// elements[0] is the long string starting IWAP01
let dateStr = elements[0].substr(6,6) // eg "190215" 15th Feb 2019
answer.date = new Date(Number(dateStr.substr(0,2))+2000, Number(dateStr.substr(2,2))-1, dateStr.substr(4,2)) // 080524 - date
answer.valid = (elements[0].substr(12,1) === "A") // flag true or false - A or else
if (answer.valid) {
let degreesN = Number(elements[0].substr(13,2))
let minutesN = Number(elements[0].substr(15,7))
let ns = elements[0].substr(22,1) // N or S
let degreesE = Number(elements[0].substr(23,3))
let minutesE = Number(elements[0].substr(26,7))
let ew = elements[0].substr(33,1) // E or W
node.warn(`${degreesN} ${minutesN} ${ns} ${degreesE} ${minutesE} ${ew}`)
answer.latitude = degreesN + minutesN/60 // 2232.9806N
if (ns === "S") answer.latitude = -answer.latitude
answer.longitude = degreesE + minutesE/60
if (ew === "W") answer.longitude = -answer.longitude // 11404.9355E
} else {
answer.latitude = 0
answer.longitude = 0
}
answer.speedMoving = elements[0].substr(34,5) // 000.1 ...a convertir en Km/h
answer.angleDirection = elements[0].substr(45,6) // 323.87 a convertir en ° (degrés)
answer.GSMsignal = elements[0].substr(51,3) // 060
answer.satellites = elements[0].substr(54,3) // 009
answer.batteryLevel = elements[0].substr(57,3) // 080
// LBS datas
answer.mcc = elements[1] // 460
answer.mnc = elements[2] // 0
answer.lac = elements[3] // 9520
answer.cid = elements[4] // 3671... Enlever le #
// WIFI bases : quand le flag est else (datas invalid), il faut pouvoir récupérer les bases wifi sur le modèle ssid|macAddress|WIFIsignal quelque soient leurs nombres... j'ai essayé et c'est pas bon du tout!!
// let i;
// answer.basesWIFI = []
// for (i=6; i<6+answer.cid; i++) {
// let baseElements = elements[i].split(/[|]|[&]/)
// answer.basesWIFI.push({ssid: baseElements[0], macAddress: baseElements[1], WIFIsignal: baseElements[2]}) // Home|74-DE-2B-44-88-8C|97&Home1|74-DE-2B-44-88-8C|97&Home2|74-DE-2B-44-88-8C|97&Home3|74-DE-2B-44-88-8C|97
//}
msg.payload = answer
return msg |
Partager