I’ve recently started out on NetLogo and created my first model. Now I wanted to add external communication for my model by having it connect to a message bus (in this case Mosquitto/MQTT). Basically asynchronise message passing between NetLogo and an external source of truth.
To my surprise, I didn’t find an extension that made this possible (I found a ActiveMQ extension but that’s RabbitMQ). In particular I was looking for a Tcp/Ip extension or even better a UDP based extension. I did find the http and fetch extensions but neither provided a clear path for bidirectional communication, i.e., recieving messages asynchronously.
In the end, my solution was to use the HubNet protocol instead. It provide the exact required message passing paradigm without me having to implement this as an extension. I did this by reverse engineering the HubNet protocol (which seems to be mostly serialised Java objects) and creating a fake HubNet client (using NodeJS + Node-RED). This works well and does the job.
I have two questions:
is there documentation/specification for the HubNet protocol or is the source code the definite source of truth?
is there an unspoken rule that bidirectional communication should not be done with NetLogo? I.e. is my approach beyond the intended usage of NetLogo?
I find NetLogo very approachable and useful tool for creating simulations and it would be nice to be able to test those simulations in the real world by having NetLogo communicate externally. But I haven’t really found examples of that kind of solution: NetLogo being a central control component of a larger system.
Thank you for reaching out, this sounds like a cool way to use NetLogo! Unfortunately, NetLogo does not currently provide any general networking primitives, so you would need to create an extension in order to get that functionality.
I don’t believe that the HubNet protocol is officially documented anywhere, because it’s not intended to be used externally, and it could change at any time. However, this doesn’t mean that you aren’t allowed to replicate the HubNet protocol, just that you should do so with caution since it is not officially supported.
That said, if it works it works, and it’s great to hear that you were able to find a temporary solution to the problem. But in the long term, if you are familiar with Java or Scala, I would recommend creating a simple UDP extension, so that you can be more certain of the correctness of your code and make it easier to add more functionality later. If you feel comfortable attempting this, you can visit the extension authoring documentation page to get started. Feel free to respond here or in another issue if you have any difficulty along the way!
Thank you for your clarifications, much appreciated
I have very very rusty Java experiences (going back to a pre-Scala age), so creating an extension would be, on the one hand, good practice but also much work. I guess this could be a good candidate for using some AI to generate the basis code and going from there.
In using HubNet, I did notice that it has inbuilt buffering of messages and connection tracking. These features would then have to be reimplemented or be available in a new extension, IMHO. Just implementing Udp/Tcp connection management won’t be as nice as the clean messaging layer interface that HubNet offers.
It also goes back to my second question whether there is actually a desire/need for simulations to communicate with the outside world. It did surprise me that there aren’t already existing extensions for network communication. In my case, the simulation I created is intended as the testbed for a production system, so it would be nice to have a simple way of porting that simulation into a production environment. Is that something that others also do?
Good points about the infrastructure provided by HubNet, it does make it a bit more difficult to replicate. You could certainly get some help from AI as needed, at least for Java questions (the standard models don’t do particularly well with NetLogo-specific questions).
You raise an interesting question about NetLogo interacting with other ecosystems. Since we have historically aimed for NetLogo to be a “complete package”, many users wouldn’t even consider the possibility of connecting NetLogo to other applications. However, ideas like this have come up occasionally; for example, extensions like the Python and Simple R extensions, which allow NetLogo to interface with Python and R, respectively.
If you end up making anything that you feel is worthy of sharing with the community, definitely post it on the Forum so that others can make use of it! And if it ends up being too technically challenging, we can certainly keep it in mind for a future development of NetLogo.