Close

5 July - Adapting to UDP Joystick's format

A project log for IP control for inexpensive line following robots

A project for my grandchildren to first build line-following robots then convert them to being controlled by their phones and tablets.

jedjed 07/05/2019 at 20:530 Comments

So I found an Android app that will send UDP to my address based on the position of an on-screen joystick. That is GREAT! See previous (4 July) entry for details.

The problem with the app is that it sends its own range of numbers with no tailoring except direction and centering. That means that the program that runs in the ESP8266 NodeMCU needs to change. The "complete" ESPLineMouse.ino turns into ESPLineMApp.ino. The process of turning the joystick position numbers into PWM duty cycle numbers for the motors also needs to move there. The monitoring code left in the application means that I can test at my desk without the robot. I go back to this configuration:


This gives me everything I need to develop and test. The brightness of the LEDs shows the duty cycle that the motors would see, so I can even test that!

A bit of work and ESPLineMApp.ino is performing well. I'm posting it now.

Now that I've changed the protocol that the target NodeMCU expects to match what the Android UDP Joystick app sends, I also need to change my test shell script AND my web page's backing CGI script. To make this easier, I find CGI.pl and add it to my Pi's library. It just takes "apt-get install cgi.pm" and apt-get figures it all out.

While I'm at it, I enhance the CGI to retrieve the target IP from a table based upon the IP of the requestor. I also add a simple page to set that target and another to list all the table entries. Old fashioned Perl CGI.pl makes it easy, for an old fashioned programmer.
The original sendudp.sh becomes sendudp2.sh below

#!/bin/bash -x
IP=192.168.95.111
# test sending UDP packet (only in bash) in UDP Joystick format
# halfway up right side
echo -n "1996162515001500" >/dev/udp/$IP/4949
sleep 3
# top near center
echo -n "1596195515001500" >/dev/udp/$IP/4949
sleep 3
# joystick neutral position
echo -n "1500150015001500" >/dev/udp/$IP/4949
#

Mouse.html only changes the name of the cgi it calls to set the IP address of the target. This is now filled in with something real - ipinput.html. Once an IP is input, ipinput.html uses setip.cgi to add it to a table and return a screen. After setting, you have a chance to list the whole table using ipdump.cgi. To get all this to work, I added a directory for the datafiles called /var/www/cgi-bin/datafiles and changed its ownership with chown  www-data.www-data datafiles. That permits the CGI scripts to write there.

Now to post the new and changed files.

Discussions