This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Get data from json format!!!
#1
Hi everyone, I'm having a bit of trouble getting data from this json code!
[ {
"EventID" : "11223344556677889900",
"EventDateTime" : "2012-04-14T13:03:20",
SALTO HAMS……p.321
"EventTime" : "13:03:20",
"EventDateTimeUTC" : "2012-04-14T11:03:20Z",
"OperationID" : 17,
"OperationDescription": "Door opened: key",
"IsExit" : false,
"UserType" : 0,
"UserName" : "John Smith",
"UserGPF3" : "Marketing department",
"DoorName" : "Gym",
"DoorGPF1" : "Leisure area",
} ]
I want to get the information of the "OperationDescription" line to be able to know if the key is open or closed. Specifically will send it to address 1/1/1
So what should I do Sad . I am a newbie, so everything is very new, please help.
I am very thankful but people !

Attached Files Thumbnail(s)
   
Reply
#2
Do you have some documentation on how this streaming protocol works? The string that you've posted is not valid JSON.
Reply
#3
Sorry you ! I just found this today, I don't know if it helps? Sad
oh, if it's not a correct structure, is it XML?

Attached Files
.pdf   SALTO DATA STREAM.pdf (Size: 1.27 MB / Downloads: 14)
Reply
#4
Create a resident script with 0 sleep time. In Salto set transport layer mode to UDP, use LM IP as Host name and set port to 9999. Check what you get in Logs tab in LM when an event happens on the Salto side. Keep message format as JSON to check whether JSON is valid or not.
Code:
if not server then
  require('socket')
  server = socket.udp()
  server:setsockname('*', 9999)
  server:settimeout(60)
end

data = server:receive()
if data then
  log(data)
end
Reply
#5
hi thank admin !I will try it
Reply
#6
Hello ! It's been a while since I texted you. I can only try it now. It outputs the LOG section like this:
---------------------------------
* string: [
{
"EventDateTimeUTC": "2023-02-07T03:33:58Z",
"OperationID": 17,
"OperationDescription": "Door opened (key)",
"UserName": "MASTER",
"DoorName": "201"
}
]
------------------------------
Can you help me? For example, now I want to get the values of the fields in "String" , for example "MASTER" or "OperationID" to assign to an address 1/1/0 ?
Thank you very much !
Reply
#7
This will write UserName to 1/1/0 and OperationID to 1/1/1:
Code:
if not server then
  require('socket')
  server = socket.udp()
  server:setsockname('*', 9999)
  server:settimeout(60)
end

data = server:receive()
if data then
  data = require('json').pdecode(data)

  for _, event in ipairs(data) do
    grp.write('1/1/0', event.UserName)
    grp.write('1/1/1', event.OperationID)
  end
end
Reply
#8
Oh, thank so much ! Done...
Thank admin very much Smile)
Reply


Forum Jump: