problems converting from JSON to GPB

48 views
Skip to first unread message

Andre Maree

unread,
Dec 12, 2017, 8:28:53 AM12/12/17
to SiteWhere
We are trying to convert an application from using JSON for mote<>sitewhere communications and have run into some problems.

#1 When sending alerts via JSON we add the "Level" metadata to indicate the info/warning/error/critical.
In the standard GPB definition at 
 the Level field is not present. Any specific reason?

#2 In order to transfer a table with information (essentially a binary structure array) we need to create the following protobuf structure

message Irmacos {
message Identity {
required Commands Command = 1 ;
required fixed64 Id = 2 ;
required fixed32 tNA = 3 ;
required fixed64 Mac = 4 ;
required int32 Chan = 5 ;
required sint32 X32a = 6 ;
required sint32 X32b = 7 ;
}

message IdentCreate {
required Commands Command = 1 ;
required uint32 Count = 2 ;
repeated Identity Identities = 3 ;
}
}

Using the API to setup a system device command we are unable to create the same structure. From what we can see the underlying code for the API does not support this, although doing with JSON is possible.

Any suggestions?

Andre

Derek Adams

unread,
Dec 12, 2017, 11:43:26 AM12/12/17
to SiteWhere
Hi Andre,

Regarding the first question about the missing alert 'level' field, I don't think it was left out intentionally. For now, you could pass the alert level in metadata, but the APIs do need to be updated to carry the level as well. We are already doing that and a lot more in SiteWhere 2.0 as we have made a protobuf specification for every object in the SiteWhere domain model as well as wrapping the RPC calls for all APIs in GRPC. 

Regarding the second question, it should be possible to transfer the table as a device command. If you store the current table as metadata on the device assignment or site, you could use a Groovy command encoder to create the protobuf command output. The hard part is that you would not be able to use any generated stubs for the protobuf encoding because there is no easy way to make them available on the classpath. You would instead have to use the low-level protobuf object model to build the message, encode it, then return it as an encoded command.

Hope that helps!

Kind regards,
Derek

Alessio Harri

unread,
Dec 12, 2017, 12:15:30 PM12/12/17
to SiteWhere
Hi Derek , I work with Andre.

The data that makes up the "record" is not stored as metadata on Sitewhere but is pulled from various columns on various tables in our application database.
I have to pull this data together and send it to the device using the device command via the REST API.
But I can only setup device commands in Sitewhere to send one record at a time as various parameters , it doesnt handle collections.
So it is possible to send a collection of data in one device command invocation via the REST API and to test it using the admin UI?


Regards
Joe


Derek Adams

unread,
Dec 12, 2017, 12:26:31 PM12/12/17
to SiteWhere
Hi Joe,

One option would be to encode the external collection into JSON or some other intermediate format and pass that value as a single parameter to the command. Then in the command encoding logic, you could parse the parameter into the individual components if needed. Is this a case where the payload contains the list of devices that need to be addressed by the command, or is this command intended for a single device?

Regards,
Derek

Alessio Harri

unread,
Dec 12, 2017, 12:48:02 PM12/12/17
to SiteWhere
Hi Derek

I thought of sending all the data as a json string or some other format and then having it decoded down the line but was wondering if I was missing something obvious.
Each device will get this message and it is used to control usage of resources etc.

Thanks for your help.
Reply all
Reply to author
Forward
0 new messages