THE DESIGN CYCLE n BY FRED EADY
Smartphone App
Programming
for Remote Control
T
here’s almost nothing you can’t do with a smartphone. However, if you want to cook up
something special for yourself using your iPhone or Android device, it’s advantageous
to have tools that help you get your arms around smartphone app programming.
You don’t know it yet, but if you can think and code in the Basic and/or C language, you
actually have a firm grasp on smartphone app programming. In this installment of Design
Cycle, we’ll code an iOS app that can be run on an iPhone or iPad. Using the same coding
paradigm, we’ll code the other side of our app to target an inexpensive WEMOS device
based on the ESP8266.
Coding the Remote Device
Sub Process_Globals
Public Serial1 As Serial
Private server As WiFiServerSocket
Private wemosPins As D1Pins
Private;espWifi;As;ESP8266WiFi
Private astream As AsyncStreams
Private switch0 As Pin
Private switch1 As Pin
Private;switch2;As;Pin
Private switch0State As Boolean
Private switch1State As Boolean
Private;switch2State;As;Boolean
Private ser As B4RSerializator
End;Sub
The WEMOS D1 Mini posing in Photo 1 is based
on the ESP8266. Since the ESP8266 is involved, that
implies communications between the remote Mini
and our iPhone will flow over Wi-Fi. The WEMOS Mini
can be programmed in many ways. We’ll take the B4R
programming path.
B4R is a free programming platform that is geared
towards the Arduino. B4R also has a special place in its
heart for the ESP8266. Our goal is to code the D1 Mini
as a remotely controlled Wi-Fi node. The code we’ll write
will toggle the Mini’s output pins. Using the logic levels
available at its I/O pins, you can drive relays, LEDs, etc.
We won’t get deep into the inner workings of each
line of B4R code as you can easily go to the B4R website
and look up any mnemonics you don’t readily understand.
You’ll find that B4R source code is self-documenting and
easy to follow.
Let’s begin by laying out our Process Global
assignments:
n PHOTO 1. This little module has replaced having
to fabricate special printed circuit boards and write
complicated TCP/IP code.
52 February 2018