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.
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
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.
First of all, it is needed to have the tftp client and Telnet. We will have to download it using the following command:
sudo apt-get install tftp && 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.
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.
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
We can enter by the time we have made a reset into the PLC wheter 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.