JZH85F
Hi,
I'm just new to this forum and OpenPLC.
I was looking for a flexible solution to manage several systems at home, including rain water tank management and other pump controls, and I found that an ESP32 platform could be the right device.
I was using in the past a LOGO relay from Siemens, but it didn't support network communication, and now that I have successfully implemented an ESP32 in a photovoltaic project to build a router for water heater management, I have appreciated the amount of features of this device, including the fact that it runs with FreeRtos, that I also quite well know.
 
Knowing that I made my first PLC program on OpenPLC today, it runs on the target, and I'm a really newbie, my questions are:
  • how can I implement protocols like MQTT or modbus TCP in the target to get a minimum of IO states (analog value of water level for instance), and is it possible ? The Idea is to use these information to dispaly them in a Homeassistant dashboard.
  • how will I be able to add a layer in the device to manage data on a CAN bus, which is also a feature of the ESP32 ? I have currently a part of the house which is fitted with a CAN bus and HAPCAN project devices.
  • is it possible to merge the compiled package produced and uploaded in the target with some other pieces of custom functions running in parallel to the PLC in a simple way ?
thanks
Reply 0 0
thiagoralves
  1. On the device -> configuration screen, where you pick the target device you want to program, tick "Enable Modbus TCP", fill out parameters. Done!
  2. Easiest way is to write a C/C++ Function Block with your CAN code. Click on the blue + button, select Function Block, and pick C/C++ as the language. This is a regular Arduino sketch where you can write any Arduino-compatible code. Add the block to your main program and you're done.
  3. Point 2 is your best bet.
Reply 0 0
JZH85F
Point 2 is your best bet.
thank you for your reply.
I have configured the device with Modbus TCP, and I tested one configuration, but I have changed something and it does no more display as expected on Homeassistant (it had worked, but I don't remember what I have changed)
which address field value should be used for the IOs in HA ? I have set both to 0, am I right ?
I have a push button and a led on an output pin, pushing the button makes the output toggle, this works perfectly on the target, here is my configuration.yaml:
modbus:
  - name: modbus_hub
    type: tcp
    host: 192.168.1.118
    port: 502

    delay: 0
    message_wait_milliseconds: 30
    timeout: 5
    
    switches:
      - name: LED
        address: 0
        device_class: switch
        scan_interval: 1
        unique_id: LED
    binary_sensors:
      - name: BP
        address: 0
        device_class: running
        input_type: discrete_input
        scan_interval: 1
        slave: 1
        slave_count: 0
        unique_id: BP
 
Reply 0 0
thiagoralves
You will have to reach out to home assistant people to get help with this
Reply 0 0
JZH85F
You will have to reach out to home assistant people to get help with this
ok, I'll do that.
is there a limitation with the outputs in the target binary produced, I mean I have made the HA work for both my input (BP) and output (LED) by using binary_sensors for both, output type set to coil, I can see the states change in HA, but I cannot write into the Output, is it a security feature from OpenPLC ?
Reply 0 0
thiagoralves
You can’t write to outputs that are controlled by your program. Whatever you write will be immediately overwritten by what the program does.
Reply 0 0
JZH85F
You can’t write to outputs that are controlled by your program. Whatever you write will be immediately overwritten by what the program does.
yes, of course ... I suppose that this can be done with variables... not written by the program.
Reply 0 0
thiagoralves
Yes, if you declare variables on %QX or %QW locations that are only read by the PLC program (never written to) then you will be able to write from Modbus just fine.
Reply 0 0
JZH85F
Yes, if you declare variables on %QX or %QW locations that are only read by the PLC program (never written to) then you will be able to write from Modbus just fine.
Nice! I will do that when needed. OpenPLC is great 👍, I've added an analog input to supervise my water tank, it works fine.
thank you for your help.
I'll come back when ready to work on the CAN bus.
Reply 0 0
fg71
I have read your first message I have this to tell you.
 
  1. Your sensor data is ESP32 so you could use OpenPLC and Modbus TCP server.
  2. You activate Node-Red inside Home Assistant, configure Modbus TCP client to get sensor data from MCU.
  3. You could bridge the data between Node-Red and Home Assistant so you could use (standard Home Assistant Dashboard) or use step 5
  4. You could setup MQTT in Node-Red to publish the sensor data to MQTT server.
  5. You could also use Node-Red to build dashboard with your sensor data.
Other approach is to use ESPHome and skip OpenPLC, and use Home Assistant (install ESPHome) and get sensor data to your dashboard.
Reply 0 0
JZH85F
I've declared a global variable %MW0, but at which address is it located in the target ? I also tried %MX0.0, but I can't find it
Reply 0 0
thiagoralves
Reply 0 0
JZH85F
thanks a lot for the link.
first, I was using a bool for the global var, and not the right formula for the location.
Now I'm using %MW0, as INT, with an initial value of FFFF, and I can find that value with a modbus scanner, at the right place !
and my program also works with the combination of the memory value and the function blocks involved.
Reply 0 0
JZH85F
I have read your first message I have this to tell you.
 
  1. Your sensor data is ESP32 so you could use OpenPLC and Modbus TCP server.
  2. You activate Node-Red inside Home Assistant, configure Modbus TCP client to get sensor data from MCU.
  3. You could bridge the data between Node-Red and Home Assistant so you could use (standard Home Assistant Dashboard) or use step 5
  4. You could setup MQTT in Node-Red to publish the sensor data to MQTT server.
  5. You could also use Node-Red to build dashboard with your sensor data.
Other approach is to use ESPHome and skip OpenPLC, and use Home Assistant (install HomeESP) and get sensor data to your dashboard.
thanks for your post.
At this time, I have solved my issue, see the previous post (sorry for my delayed reply), but I take good note of your suggestions, I will look at this in a while.
I add this to the document I'm building as usually when I discover something new...
Reply 0 0
Reply