gama-platform / gama.old

Main repository for developing the 1.x versions of GAMA
GNU General Public License v3.0
303 stars 99 forks source link

Enhancing MQTT tool to connect non-gama models #3883

Closed leonsi7 closed 9 months ago

leonsi7 commented 12 months ago

Is your request related to a problem? Please describe.

First problem I'm working on using MQTT to couple GAMA model with other models. When I use do connect and do send in order to create a MQTT message, the problem is that if I send a content such as a string, it creates automatically a xlm to enclose the message. For example : If I send the message test, I would get:

<ummisco.gama.network.common.CompositeGamaMessage>
  <unread>true</unread>
  <sender class="string">sender</sender>
  <receivers class="string">receiver</receivers>
  <contents class="string">&lt;string&gt;test&lt;/string&gt;</contents>
  <emissionTimeStamp>44</emissionTimeStamp>
</ummisco.gama.network.common.CompositeGamaMessage>

Here tou can see that test is sourrounded by a lot of unuseful information.

Second problem A second problem appears when I use stringified JSON. For instance, let's consider the following map: map(["x"::10,"y"::20]), the sent essage (without the sourrounded xml) is {&amp;quot;x&amp;quot;:10,&amp;quot;y&amp;quot;:20}}, which is not expected because I expect {"x":10,"y":20} for my JSON parser.

Describe the improvement you'd like I would like to add a new parameter for the send function, something like send_raw:True which would send the raw message without the xml and using character such that " and not &quot.

Describe alternatives you've considered The only current alternative is to use the second model or and api to denoise the mqtt message (removing xml and replacing useful character for JSON by the right one).

Additional context None

hqnghi88 commented 12 months ago

Hi, did you try facet raw:true in the connect statement? It was the same case for other protocol and need to be Raw. 2nd, try operator to_json to get the correct json formatted string , i think.

leonsi7 commented 12 months ago

Hi, for the first thing : My code has

do connect to: "localhost" port: 1883 login:"admin" password:"admin" with_name: "sender" raw:true;

And then :

do send to:"receiver" contents: as_json_string(message_location);

Where we have

map<string,map> message_location;

And I receive the something like the XML above. The facet raw is designed only for TCP and Websocket as mentionned here

For the second part, I actually used the function as_json_string(message_location) as mentionned above.

lesquoyb commented 9 months ago

now mqtt servers should take into account the raw facet, can you test if it fits your needs @leonsi7 ?

lesquoyb commented 9 months ago

I consider that it works now, if you see any problem with that implementation feel free to reopen @leonsi7