znelbok
Hi all

I have just found this site and all the goodness that it is.  I am having fun setting up everything and now I am at the point of starting to program.

I have spent my career writing code in function blocks (DCS') and never gotten the change to use ladder or structured text.

I am attempting to write something in ST right now but would like to see some example projects so that I can learn from them.  I am reading some small tutorials but thats not my style of learning, examples and doing is how I best learn.

SO if anyone has some projects that they wouldn't mind posting in ST that would be awesome  Even the Hello World in ST would be a good start.

Thanks
Reply 0 0
thiagoralves
The good news is that PLCopen Editor translates everything into ST code. That's the base language for OpenPLC. So, if you get the Hello World example and go to file->generate program you will end up with the Hello World in ST language. Just open the file in a text editor and you will see the code
Reply 1 0
znelbok
Excellent Thanks

Was a big help.
Reply 0 0
astang

Hello,

I have some questions/problems: 
--------------
The first (1)
--------------
I also tried the "Hello World" example project from:  http://www.openplcproject.com/getting-started-esp8266

* my Raspberry as a PLC and
* the ESP8266 as my field devices (with button and a lamp)
and that works totally fine. I can upload the configuration file via the webinterface and I can also upload the PLC Pprogramm. It compiles without errors.

BUT When I look at my ESP8266 and press the button the lamp doesn't light up.
(I already tested the lamp and the button before, they aren't broken)
What could be the problem?

* First Screenshot shows what I uploaded
* Picture Four shows the real ESP8266 

--------------
The second (2)
--------------
I tried to use the Structed Text (because I really do not get the Ladder Logic and Structured Text seems similar to C, Arduino IDE)

BUT something doesn't work. I got and fixed already many error messages but I don't understand the last Error message (See the picture below).
Can you help me? 

* Second Screenshot shows the Structured Text
* Third Screenshot shows the Error Message from the Webinterface
* Picture Four shows the real ESP8266 


Kind Regards
Alice

Reply 1 0
astang

because the pictures I send before are so small here again, the Second Screenshot:

170226_Structured_Text.png 

Reply 0 0
thiagoralves
About your first problem, you must check to see if the ESP8266 is actually connected to the OpenPLC running on your Raspberry Pi. Did you upload the OpenPLC firmware to the ESP8266? Are you using the ESP8266 driver on the Raspberry Pi? What are the logs during runtime when you’re executing your program (just click on PLC logs in the web interface)?

About your second problem, it seems that your issue is not in the code, but in your configuration. Post your project (xml file) here in a zip file and I’ll take a look
Reply 1 0
astang

Thank you so much for you quick response!

-----------------------
(1) Problem
-----------------------

1. yes it is, I always open three windows at the Pi Terminal
       * one for the connection
       * one for the Start Nodejs Server.js
       * one for other things to check --> like to check if the IP adresses and the MAC adresses fits still together)
--> for me it seems like this works "wlan0: MAC-Adresse: WPA: pairwise key handshake completed (RSN)"

2. Yes I uploaded the firmware from here: http://www.openplcproject.com/getting-started-esp8266

3. I uploaded the Config file, there I wrote down the ESP8266 information like with .

    Num_Devices = "1"

   # ------------------------
   # Device 3: LED and Button
   # ------------------------
     device0.name = "MB Slave - Inputs"
     device0.protocol = "TCP"
     device0.slave_id = "3"
     device0.address = "192.168.1.13"
     device0.IP_Port = "502"
     device0.RTU_Baud_Rate = ""
     device0.RTU_Parity = ""
     device0.RTU_Data_Bits = ""
     device0.RTU_Stop_Bits = ""
     device0.Discrete_Inputs_Start = "0"
     device0.Discrete_Inputs_Size = "8"
     device0.Coils_Start = "0"
     device0.Coils_Size = "4"
     device0.Input_Registers_Start = "0"
     device0.Input_Registers_Size = "10"
     device0.Holding_Registers_Start = "0"
     device0.Holding_Registers_Size = "5"

4.  During the Upload: 170226_Logs_during Upload.png      
4.1 After finishing upload:

       170226_Logs.png 


-----------------------
(2) Problem
-----------------------

* I attached the OpenPLCEditor XML as .zip

Reply 0 0
astang
--------------------
(2) Problem
--------------------

* additionally: The ESP8266 firmware which I uploaded on the ESP8266
   (I just changed the Port to 502 and my IP Adress and the Device-ID)
Reply 0 0
thiagoralves
You’re making a few mistakes here with your ESP8266 connection. Clearly from the logs, you’re not using the ESP8266 driver on your Raspberry Pi. The ESP8266 driver prints on the logs that it is looking for ESP8266 devices waiting for connection. You should see something like this in your log:

ESP8266: Listening on port 7567
ESP8266: waiting for new client...

If you don’t see that, it means that the ESP8266 driver is not present. When you finish installing/building OpenPLC on your Raspberry Pi, you must check the ESP8266 option if you’re planning to work with ESPs.

Also, you don’t upload any config file to work with ESPs. That config file is for Modbus slave devices only, and is only needed when you’re using the Modbus Master driver. The OpenPLC firmware you uploaded to your ESP only communicates with the ESP8266 driver installed on your OpenPLC host.

About your project file, I’ll take a look at it later and get back to you.
Reply 1 0
astang

I am totally new in this whole network and OpenPLC area. I really understood it quiet wrong.
 
Yes you are right, after the installing process of OpenPLC on my Raspberry Pi finished I chose "4) Raspberry" and not ESP8266.  

Okay, than I will start to install the Raspberry Pi again but this time I will choose ESP8266 and try everything again. 
This will take a while.
I will let you know If this solves my problem.

thank you so far!

Reply 0 0
thiagoralves
I looked at your program and as I suspected, the problem is in the configuration. It seems that you reused the Hello World example project to create your new project, which is good so you don't have to setup everything again in the project, but then you deleted the original program "My_Program" in the project and created a new one called "program0". The configuration stated that the program it should run is "My_Program". Since it couldn't find it, it failed. All you have to do is go to Config0->Res0 on the left side bar and change the instance from "My_Program" to "program0":
Capture.png 

After that you should be good to go.


About your first problem, just remember to revert the port back to 7567 on the firmware, otherwise the communication with your ESP8266 driver will not work.
Reply 1 0
astang

Oh I am so sorry It took my so long to reinstall everything and check everything. 
But some good news:

--------------------------
(1) Problem: SOLVED
--------------------------
THANK YOU!
I installed it the ESP8266 driver on my Raspberry Pi and now the code compiles right AND also I can press the button and afterwards the LED lights up!

--------------------------
(2) Problem SOLVED
--------------------------
@ your new Post: 
Yes that is also right I thought it might be possible to just copy and paste the variables tables from your LD but it wasn't so I just deleted the LD and create at the same project the ST. Thank you for figuring it out. 
this configuration habit is good to know for future projects. 
I changed it too: progamm0
>> and afterwards the error messages are gone

--------------------------
(2.2) Another Problem 
--------------------------
But neither in LD nor in ST I can not control another led.
I implemented %QX3.1 still just the Board LED lights up an not the implemented LED on the PIN D1 = %QX3.1

@ your new Post: I changed it too: progamm0
>> But still the only led I can control is the board led.

------------------------------
(3) Understanding Problem
------------------------------
I want to work with ModbusTCP/IP Protocoll. I read that nomally you use the 502 port for it.
So what is the difference to use
* #define SERVER_PORT 7567
* #define SERVER_PORT 502
I tried both and both worked. So just to be clear: It works both but I don't get it.


______________________
Attachment:
1) XML
2) ESP Firmware with Updated Details (Port: 7567, IP , Device-ID)

3) Picture from the Log after adding ESP8266 driver to Rapsberry  

Reply 0 0
thiagoralves

It seems that your setup is still not right. From the log that you posted, I can see that your OpenPLC host is not communicating with your ESP8266 at all. The last ESP8266 message you see is "waiting for a new client...", but no one ever connects. If you're using the nodemcu board as your ESP8266 device, the internal LED is connected to GPIO2, which is OpenPLC input %IX3.0. This means that whenever you press a button connected to that input the LED will toggle, because it is physically wired to do so, and not because OpenPLC program is running properly.

You need to make sure that both ESP8266 and your Raspberry Pi are on the same network. Then you need to verify that the ESP8266 has actually connected to the OpenPLC host. You may want to open the serial monitor on the Arduino IDE at 115200 baud to check the logs from your ESP8266 device as well. Maybe you put the Raspberry Pi IP wrong, or maybe is something else. When the ESP8266 connects, you should see a message like "ESP8266: Client accepted! Creating thread for the new client ID: x" on the OpenPLC logs. If you don't see that message, it means that your ESP8266 board is not connected.

The 502 port is used for Modbus TCP communications. The ESP8266 does not talk Modbus. It is supposed to use port 7567 to talk directly to OpenPLC's ESP driver and send/receive IO information. If you try to use port 502 to communicate with your OpenPLC host, the ESP board will try to connect to the Modbus server and it won't work. After you finish your setup and have verified that it is working, you can use Modbus/TCP software to communicate with your OpenPLC host and query data. Don't use Modbus software to communicate directly with your ESP board because it won't work.

Reply 1 0
astang

thiagoralves wrote:
This means that whenever you press a button connected to that input the LED will toggle, because it is physically wired to do so, and not because OpenPLC program is running properly.

--> okay I understood it now. Thank you! 

-------------------------
(2) Problem: SOLVED !!!
--------------------------
again Thank you!
thiagoralves wrote:
Then you need to verify that the ESP8266 has actually connected to the OpenPLC host. 

I checked it again and It seemed I put a "1" too much behind the actual server-IP
 * WRONG: #define OPENPLC_SERVER_IP "192.168.42.11" 
 * RIGHT: #define OPENPLC_SERVER_IP "192.168.42.1"
unnecessary mistake. Thanks for the note!
--> Now It really works! I can push the button and the right implemented LED lights up. Thank you so much!

thiagoralves wrote:
 When the ESP8266 connects, you should see a message like "ESP8266: Client accepted! Creating thread for the new client ID: x" on the OpenPLC logs. If you don't see that message, it means that your ESP8266 board is not connected. 

--> That was really helpfull! Now I know exactly for what I have to look. (For all unknown persons like me I have attached a picture again)

-------------------------
MODBUS TCP/IP
-------------------------
thiagoralves wrote:
After you finish your setup and have verified that it is working, you can use Modbus/TCP software to communicate with your OpenPLC host and query data. Don't use Modbus software to communicate directly with your ESP board because it won't work.

* Thanks for the further hints I will consider it tomorrow
Reply 0 0
astang

thiagoralves wrote:
The 502 port is used for Modbus TCP communications. The ESP8266 does not talk Modbus. It is supposed to use port 7567 to talk directly to OpenPLC's ESP driver and send/receive IO information. If you try to use port 502 to communicate with your OpenPLC host, the ESP board will try to connect to the Modbus server and it won't work. After you finish your setup and have verified that it is working, you can use Modbus/TCP software to communicate with your OpenPLC host and query data. Don't use Modbus software to communicate directly with your ESP board because it won't work.


I understood now that the ESP8266 is not able to talk Modbus and that the #Port 7657 is it not another Port for Modbus TCP/IP Protocol.

BUT can I ask you what exactly is the #Port 7567, why it is exactly the #Port 7567 ?
I wonder about this specific number, does it refer to a specific protocol? If yes how it is called?

Reply 0 0
Reply