Introduction
In this post, it will be seen how to send the binary file of an sketch into Arduino using Ethernet with tftp Client. Furthermore it is needed to use Telnet in order to do a remote reset. As in the step 2 of this process this post will be divided in two different parts. One for sending the binary file using Windows and the other using Linux.
Windows
For sending a sketch using the tftp Client it is needed to activate the tftp on the Windows Feature. Also, it is needed to add Telnet in order to send a remote reset to the PLC. (Only an upload can be made if the Arduino is boot loading. This is why we need the reset). If you follow this link you will see how to activate these services on Windows Feature
http://www.trishtech.com/2014/10/enable-tftp-telnet-in-windows-10/.
We also need to have an IP range compatible with 192.168.1.128 so you have to define an IP with this range, like 192.168.1.129
Once we have the services activated we just need to go to the prompt Shell of Windows. Also known as CMD.
In there we will just need to go to the path of the .bin file using the “cd” command. This operation will be done two times (in two different prompts). if we are going to use the remote reset. (Take into consideration if you can remote reset, visit this link for more information).
Once we are prepared, having the CMD in the correct directory we just can send the binary file using a command. In order to succeed the PLC is going to receive the code that has to be bootloading. The PLC is booloading by the time it resets so it is really important to send the binary file just after we reset.
To remote reset, we will use the following commands in the prompt.
->Telnet ->open 192.168.1.128 open a
To upload the binary code we will use the following command.
tftp -i Host PUT sketch.bin
- Host -> 192.168.1.128 The IP of the booloader
- sketch.bin -> sketch_nov20a.ino.bin The sketch we want to upload
Now the code is uploaded into the PLC.
It can appear some setbacks that can make fail this tftp communication. The main problem is the Firewall of Windows. So if you follow all the steps and by the time you want to send the binary file it doesn’t respond maybe the firewall of Windows is responsible. In our case, we had to disable the firewall of Windows in order to achieve this uploading.
Linux
First of all, it is needed to have the tftp client and Telnet. We will have to download it using the following commands:
sudo apt-get install tftp
sudo apt-get install telnet
After that we need to stablish an static IP if we don’t have it having connected already the Ethernet wire that connects the PC and PLC in order to create an interface for this network.
Now everything is set up for uploading the code into the PLC.
So we need to open 1 terminal (2 if you are going to do the remote reset. Check the link ).
The final result would be something like this if we are using the remote reset, if not we will just need the right terminal. We will see how we get into that.
Remote reset
The command we will use to send the remote reset is the following one:
$ telnet HOST PORT $ a
HOST -> IP to talk, in my case 192.168.1.211
PORT -> Port to establish the communication. By default 2000.
A remote reset will be not possible if an sketch like the example in the link above is not already uploaded to the PLC. To upload the sketch for the first time, a manual reset or a USB cable must be used because you will not be able to reach telnet.
TFTP Client
For using the tftp client we need to establish some functionalities in the tftp client.
We will need to use the following commands:
$ tftp HOST PORT mode octet trace verbose put sketch.bin
HOST -> IP of the bootloader, as the Readme from the bootloader says, 192.168.1.128
PORT -> Port to establish the communication. By default 69.
We can enter by the time we have made a reset into the PLC whether being a remote reset or a manual reset. If we succeed we will see how the binary file is being sent.
Now we will have the uploaded code into the PLC.
If not, a "Transfer timed out." message will appear. This can be solve by resetting the PLC and trying again. If the message keeps appearing, check you have done all the steps correct.
Upload a sketch to an Industrial PLC using Ethernet - Step 3 - TFTP Client