This is the homework project for the SE 423 Mechatronics course at UofI. The requirement was to use the MSP430G2553 Launchpad and RC Servo(s) to do something cool.
I decided to purchase an ESP8266 WiFi Transceiver module due to the (1) enticing price, (2) endless opportunities for future projects, and (3) the current lack of documentation for interface with the MSP430G2553 Launchpad.
There are multiple firmware replacements, such as NodeMCU, that can be downloaded onto the ESP8266 to further expand the capabilities; however, I opted to stay with the default AT Command set. AT Commands
With the AT Commands, each message is preceded by AT and must end with both a carriage return and a new line \r\n. When beginning, one should send the simple command: AT\r\n. If everything is working properly, the ESP8266 will reply with OK.
A great feature of the AT Commands is the ability to set certain modes for either the current session (_CUR) or every time, saved in flash (_DEF). Saving in the flash allows you to not run the same code each time the system is powered on. This is only available in a couple command sets.
Note that if you mess up too much, it may be useful to run the command AT+RESTORE (followed with \r\n), which resets all of the parameters in the flash, as well as running a full factory reset.Connect to WiFi
The first command that is to be set to connect to WiFi, is AT+CWMODE_DEF=x. This can be called to either save it in the flash, or just for the current session. The value that this is set to (x in the above) is either 1 (Station Mode), 2 (SoftAP mode), or 3 (SoftAP+Station mode). Where station mode is when the ESP acts as a client, and the SoftAP mode means the ESP is acting a a Software Enabled Access Point. For simply connecting to WiFi, I use AT+CWMODE-1.
Next, we need to actually connect to our router, using AT+CWJAP_DEF=SSID, Password. The SSID and password are those of your router. Because this is a decent amount of text, you may want to break it up into separate printf statements using the escape character "\". Set ESP8266 as TCP Server
For this, I enable multiple connections. This is done by using the AT+CIPMUX=x command, where the x is 0, for single connection, and 1 for multiple connections. Next, we want to create a server using AT+CIPSERVER=#, Port. Where # is the connection number of the server and Port is the port in which you want the server. Next, in order to connect to the server, you need the IP address. This will be sent in response, along with the Mac address, to AT+CIFSR.Send TCP Messages From ESP8266 to Phone
To first begin a TCP Connection with our phone, use the TCP Server app on your WiFi network and enter a port. Send the command AT+CIPSTART=#, IPAddress, Port. Where # is the connection number, IPAddress is your phone's IP (this should be displayed on the TCP Server app), and Port is the Port number you input to the TCP Server app.
To send an actual message, we must send two parts. First, use AT+CIPSEND=#, len, where # is the connection number and len is the length of the message you will send. Make sure to include 2 extra characters for \r\n if you are displaying this on a screen. Send your newline and carriage return with this. Now, to send the message, note that this uses a rare exception to the AT Command set where the message is not preceded by AT. Simply send the message. The ESP will continue to read every incoming character to it as part of this message until it fills the buffer of specified length (len).