Unfortunately, you can’t just communicate with the
server’s router because the port number being used is
associated with a particular computer on the LAN — not
the router. Fortunately, routers have a way of forwarding
messages received to the computer using the specified port
(which explains why no two computers on an LAN can use
the same port number). To set up PORT FORWARDING,
you have to log into your router. This sounds a lot more
complicated than it actually is.
If you don’t have your router’s manual available,
typically you can get its IP address (and its default user
name and password) by looking it up on the Internet (just
search for your router’s manufacturer and model number).
Type in the IP address on your browser, log in, and navigate
the menus to find PORT FORWARDING.
The actual procedure for setting up PORT
FORWARDING is different for different routers, but usually
it is straightforward. All you do is enter the port you
want to forward to (42001 in this example) and the local
IP of the machine you are using for the server program.
The router will do the rest. Essentially, if the router gets
a message addressed to a particular port on your LAN, it
forwards that message to that port on the machine whose
local IP you specified when you set up PORT FORWARDING.
Generally, you only need to perform this setup once, but
in some cases, the IP addresses of various machines on your
LAN can change. Just know that it can happen, so set things
up again if your communication fails sometime in the future.
Once you have PORT FORWARDING set up, just
enter the server’s IPv4 address and port number into the
client program (Figure 4), and you’ll be able to exchange
messages between any two computers in the world. With
the tests I performed with a friend in Australia (can’t get
much farther away than that), the
speed seemed instantaneous for
manually typed messages.
Controlling a Robot
Once you can receive messages
from a remote computer, it’s easy to
parse the text for reserved words or
phrases like MOVE FORWARD or TURN
LEFT and execute the appropriate
actions to make your robot perform as
expected. Such actions might require
controlling your robot’s motors directly
or by sending Bluetooth commands to
your robot’s microcontroller. Obviously,
your robot’s hardware configuration
will dictate the exact procedure
In the next issue of SERVO,
With two or three devices in a home, you can usually
give voice commands from anywhere in the house. The next
article will show how to use Alexa as a speech-to-text system
that can send messages directly to a server program (as
discussed in this article).
For now, imagine the power of being able to control
a robot that way because next time, we’ll make it a reality.
• Everything you need to learn to program PIC® microcontrollers is included in this package
• Learn the fundamental concepts of programming,
including program flow, loops, coding techniques, binary
manipulation, device-to-device communication, user
interface design, in-circuit debugging, and more!
• Includes all the necessary the software, compiler,
trainer board, cable, tutorial with exercises and sample
THE MOST COMPLETE PROGRAMMING TUTORIAL!
Academic and bulk pricing available
Check out our other popular products
for PIC® developers including:
Contact us at firstname.lastname@example.org
PICBASIC PRO™ Compiler
SERVO 09/10.2018 67