1

Parsing a JSON param with two data types

(18/12/2015 14:30:04 отредактировано nasnew)

Тема: Parsing a JSON param with two data types

Hello,

I was testing the avl_evts method but unfortunately the params in returning JSON result are some times type: int and other times object. please check http://www.awesomescreenshot.com/03c5ht4513 As you can see the event code is of type int here but some times it will have values V,ct and at. This is giving me hard times in the JSON parsing process. Please advise !!

2

Parsing a JSON param with two data types

Re: Parsing a JSON param with two data types

Hi

Dealing with avl_evts first of all you should detect event type and handle only needed and  skip all others.

Wialon send information in minimalistic style and you can detect either parameter int or object programmaticaly.

On your screenshot event type is "prms" - update message parameters and for this case:
- INT value is "time of last message with such parameter"
- Object is a new parameter state (value, ct and at)

3

Parsing a JSON param with two data types

Re: Parsing a JSON param with two data types

I have managed the difference by using dynamic data type.

In the same process of testing the avl_evts, I observed an Event content under Messages Application in Wialon and the same detail retrieved using the avl_evts are not the same, please check >> http://awesomescreenshot.com/04b5hx5pb9 for the details I got using the avl_evts and check the same detail under message here >>  http://awesomescreenshot.com/0ee5hx5xe0

As you can see the one under messages got correct details while same message retrieved via avl_evts only got Unix time for all parameters, please let me know if I may miss something.

Thanks !!

4

Parsing a JSON param with two data types

Re: Parsing a JSON param with two data types

nasnew пишет:

As you can see the one under messages got correct details while same message retrieved via avl_evts only got Unix time for all parameters, please let me know if I may miss something.

As i wrote before, when you get integer as a value - it is "time of last message with such parameter". On your screenshots i see that Wialon received message in 1450601440 (UNIX time) with 4 parameters (drvs_list_type, ...) and their value became unchanged comparing with previous message, so event just gives you to know that this parameters appeared in message with time 1450601440.

I'll try to explain how message params cache works

+ открыть спойлер

Every unit has a message parameters cache, for new unit its empty. When Wialon receive new messages - it updates messages params and triggers events, for example

Message 1
Suppose wialon get message from new unit with two new parameters {time:0, params:{a:0, b:1}}
It trigger event for this message {a:{ct:0, at:0, v:0}, b:{ct:0, at:0, v:1}}
When you get event, you update messages parameters cache of unit {a:{ct:0, at:0, v:0}, b:{ct:0, at:0, v:1}}

Message 2
When Wialon receive next message {time:10, params:{a:0,c:1}} it analyze units message params
and trigger event about parameters changes {a:10, c:{ct:10, at:10, v:1}} - parameter 'a' not changed but it presented in this message (10 - is message time in this sample), 'b' wasn't in message - so its not in event
You handle this event and update messages params cache, it should look like
{a:{ct:0, at:10, v:0}, b:{ct:0, at:0, v:0}, c:{ct:10, at:10, v:1}}

Message 3
3rd message with all 3 parameters changed comparing with their previous values {time:100, params:{a:3, b:4, c:5}}
Event {a:{ct:100, at:100, v:3}, b:{ct:100, at:100, v:4}, c:{ct:100, at:100, v:5}}
Finally, message parameters cache {a:{ct:100, at:100, v:3}, b:{ct:100, at:100, v:4}, c:{ct:100, at:100, v:5}}

Also you can check events handler sample on JavaScript on GitHub

Hope this helps

5

Parsing a JSON param with two data types

Re: Parsing a JSON param with two data types

Thanks a lot !!