I am fond of collecting action figures that of my favorite cartoons and comics for a long time. Three days ago, I found one of my old Action-Man figures not displayed on the shelf in my old room, unfortunately, its gear and snowbike were lost. Therefore, I decided to modify that dilapidated Action-Man figure to present it again. After considering options, I chose to make a laser gun controlled over the Internet and RGB lighting attached to its base as well. Because of its simplicity for me, I used my web application, which allows the user to transfer data packets without needing either a submit button or a web server hosted by the micro-controller, to send commands to NodeMCU but, of course, you can use other web applications to re-create this project, for instance, Blynk.
Required Libraries:
For NodeMCU, click here.
If you will not use my web application for this project, you can skip this step :)
First of all, to create your unique data panel connection path automatically and be able to access form information through TheAmplituhedron API, click the web application named Data Panel on your dashboard.
Now, you have to connect your page to get your form information by using a WiFi client embedded in ESP8266 libraries as default. It is simple to use and only requires two parameters – a hostname and a port number. But, TheAmplituhedron is protected by SSL so that you need to use WiFiClientSecure instead of the default WiFiClient.
WiFiClientSecure has pretty much the same usage and syntax with WiFiClient; you only need to set an SSL fingerprint to the requested server and use 443 as the port number as depicted on the code below.
client.setFingerprint(fingerprint);
SSL FingerPrint works like an ID card; when you visit a web page that of an SSL protected website, it verifies your connection secure depending on whether you have the fingerprint or not. As a result of that, every browser has a file that contains the SSL fingerprint, mostly known as ThumbPrint.
To get more information about SSL and the current fingerprint for this project, click here.
To inspect TheAmplituhedron Data Panel web application, click here.
Filter form information from a web page by splitting the response stringIf you do not use my web application or congruent applications for this project tutorial, you might not need to split the response string in Arduino IDE to gather data packets as explained below despite the salience of the delimiter method.
As ESP8266 sends a request to a specific page on a server, the page responds with a string that can be read by ESP8266, including the requested page headers and content. I programmed my web application to send form information into the page content throughTheAmplituhedron API. To separate the headers and the content, use readUntilString() with ‘+’ characters. It gives you only the page content because the page header does not include any ‘+’ character.
client.readStringUntil('+');
TheAmplituhedron API separates each input variable by using a percentage character(%), which allows you to detect and save each input variable on ESP8266.
%Switch%Range%Message%
Unfortunately, there is no easy way to split a string in Arduino IDE aside from detecting each delimiter line index to glean a substring. Therefore, I detect each percentage character as a delimiter and define a substring with the former and the latter to split the response string.
delimiter_1 = readString.indexOf("%", delimiter + 1);
Switch = readString.substring(delimiter + 1, delimiter_1);
I used a wooden stick as the base on which I attached NodeMCU by using a hot glue gun.
I connected two laser modules as laser beam guns and an RGB led as the base lighting, you can find pin connections on the source code or the schematic down below.
After that step, I fastened a laser module to each arm of the old Action-Man figure posing astride on the base and RGB lighting.
You can get three different variables from TheAmplituhedron Data Panel – Switch, Range and Message. Switch is a pre-defined button, which can be ON or OFF. Range is an integer from 0 to 255, which you can use as limit or PWM input. Message is a string up to 100 characters, which you can print as a message, scan for commands or use to create new substrings with the percentage character. If you are using my web application(Data Panel), you can view these variables on the serial port.
1 - ) Control laser modules on each arm by using the Switch.
2 - ) Activate a unique blinking pattern for the right laser beam(Laser_Right) if the Range is bigger than 180.
3 - ) Change RGB colors as background lighting by using the Message – RED, BLUE, GREEN, YELLOW, MAGENTA, CYAN.
Fetching Data via NodeMCU
Demonstration
Comments
Please log in or sign up to comment.