Neuron - Addressing GPIO from C++
@tomas_hora I see that EVOK uses PIGPIO, which uses GPIO, is it still then usable with the neuron? I actually have no idea at the moment what Mervis does, need to check the tutorials on Youtube...
Also, no knowledge on Modbus yet. I will start trying it out as soon as I have the Neuron (at a colleague's place now)
@Boy-Lenssen Since the GPIOs are not used in Neuron, than PIGPIO does not have any sence there. You could use it to write your own implementation of the low level protocol on SPI, but why?
@tomas_hora I will first check Mervis and otherwise try http://libmodbus.org/ or something. I think I'll manage, thanks!
@tomas_hora I had this project in the fridge for now, but picking it up now. I actually want to try to talk to the I/O ports via modbus, but need a bit of a start.
I understand that I need to connect via IP and port number, but how do I talk to the ports next? How do I set them to pullup/down and input / output? How do I get triggered when an input changes?
I want to try this out with Android Things IoT OS. Can I setup a modbus server myself to be able to talk to the ports?
I'm so sorry, I just can't find a way to get started...Should I install Mervis and use a second Pi with Android Things to connect to the modbus?
tomas_hora administrators last edited by tomas_hora
@Boy-Lenssen All the I/Os (except 1Wire) are acessible using the TCP Modbus protocol, the map of each register/coil can be found here
Since it does not uses GPIOs of RPi, you do not need to set any pullups. Just use the registers/coils to set and read the states of IOs. You will need to poll the registers/coils periodically to catch the state of the I/O.
I suggest you to take a look at some C++ ModBus TCP library that supports client mode.
You can also use the Websockets, or HTTP REST api that evok provides (it is using the underlaying TCP Modbus): https://github.com/UniPiTechnology/evok#testing-latest-git-versions
@tomas_hora of course! How stupid of me, no pullups etc and input/outputs are dedicated on the device.
One last question before I can start investigating: to get it working, I need to flash the Mervis image on SD card and use that on the Pi located in the Neuron, right? And then I need an additional Pi (if i want to run Android Things) to work as a client to address it?
tomas_hora administrators last edited by tomas_hora
@Boy-Lenssen You can use the Mervis which already includes teh TCP Modbus. Or the standard Raspbian and install it on your own from github https://github.com/UniPiTechnology/neuron_tcp_modbus_overlay
And yes, than you would need to run Android Things on a different RPi.
@tomas_hora Thanks for the patience! It is all becoming clear to me!
@Boy-Lenssen You are welcome :) I am glad I helped a bit...
@tomas_hora Well, it looks like more questions arise, so I think I keep bothering you for just a bit more :) But if this thing works out, we will be buying a lot more of these devices!
I am working on a project where it is quite critical we know when an input has changed. I would like to know which method is the fastest of the ones listed here: https://github.com/UniPiTechnology/evok#testing-latest-git-versions
Another thing: if I need to shut down the system (it is shut down every day), should I create something that will gracefully shut down the Pi in the Neuron (when I'm using the Mervis image) or is that SD Card read-only and is there no chance of corruption?
@Boy-Lenssen The fastest is definitely only the TCP Modbus since more SW between your calls and the HW causes more delays. The TCP Modbus server can handle easily thousand of requests per seconds. Evok does not scan that fast (by default twice per second but can be re-configured).
If you disable the mervis system (sharkrt + configtool) on the MervisOS, than there is nothing else I am aware of that will try to write to the card. So everything except Mervis shoudl be read-only, but I cannot guarantee there is no chance of corruption.
There is no ready solution for easy shutdown (except standard linux features like cronjob).
@tomas_hora I fired up the system with the december 6th version of Mervis software image (https://files.unipi.technology/index.php/s/zTmrEbQEvifNd6W?path=%2FSoftware%2FMervis).
what is the login for it? I have the Neuron connected to my screen and only get to the login.
http://192.168.1.102/rest/all (where I checked it's IP address via my router) does not return anything. It gives a 404 in the browser and wget -qO- http://192.168.1.102/rest/all does nothing. http://192.168.1.102 shows a page with a login button, so the server is running.
- The mervis services are still running, thus also its web interface on port 80 where you see the page with login. See the port of evok in /etc/evok.conf
Btw. I suggest you to disable the sharkrt and configtool services first or even get started with a clean raspbian (lite) so you do not get confused by some of tuneups that are implemented in the MervisOS.
@tomas_hora so it is normal not to have access to the REST api? I thought this was available on the Mervis image.
I just wanted to get some basics to try out, that is why I took the Mervis img
@Boy-Lenssen The mervis image does not contain the newest version of evok that supports Neurons (since it is not needed). That is only available on github as above
@tomas_hora ok, going to try it on Jessie Lite...
I am completely confused about the software that is available atm. Can you do a summary on what is what?
I see Mervis had TCP modbus, but no REST API, which seems to be part of EVOK?
I wanted to try out someting using the REST API, but on Mervis, there is only modbus?
Do I see it correctly, and Mervis contains Modbus as it uses it to communicate itself? And is EVOK a collection of UniPi API possibilities?
Edit: in meanwhile, I have installed EVOK without any issues on a Jessie Lite img and could address the REST API. The Pi I had it installed on was not the one in the UniPi. I have to use some pliers to get the SD-card out of the UniPi to replace it ;) will do that tomorrow, enough for today ;)
Edit the next morning :) : I think I understand now. EVOK is something that is in development with API's and (in future?) control the UniPi via some UI, like Mervis
Mervis is an off-the-shelve solution that already existed and works with the UniPi...
@Boy-Lenssen :) You got it all right. Evok and the TCP Modbus server are opensourse solutions for people who want to do their own implementation.
Mervis makes UniPi all in one PLC system including scada, HMI designer and database.
@tomas_hora Ok, I made the mistake by following the readme instead of getting the current branch :p
I restarted this morning, get -qO- http://192.168.1.16/rest/all does not show anything. I selected option 2 (Neuron) during setup, so all should be ok.
Can you tell me how to read / write via rest (or another way?)...how do I know what the ports are called? Also I see no web interface when going to http://192.168.1.16
What am I doing wrong?
Edit: OK! Adding port nr 8088 to the command makes it work! wget -qO- http://192.168.1.16:8088/rest/relay/2_14 --post-data='value=0' now changes the value! \o/ thanks!
Edit2: websocket via Python script is also working perfectly! But as you said TCP Modbus is faster, I might go with that one...
@tomas_hora I got it working with Modbus, websockets and REST, very cool!
You advised to use Modbus because of the speed. To see changes on the input, I need to poll the port. Do websockets push any changes so polling is not necessary?
When should I use registers to change a value, and when should I use coils?
@Boy-Lenssen Great :) Yep, the websocket automatically notifies all clients about a change of state at DI. However by default it does only twice a second so check your config.
If you want to set only a single for example relay then use coils. If you want to set multiple relays at once, use registers. But be aware that by using registers, you set all the relays mapped to the registers, so you can accidentally set relay to a different state (eg. if the state of relay changes from a different place in your app between the read and write to register).