Node.js Server and WiFi Network Signal Strength Reader

This week, we were asked to look into and work with a few different aspects of network setups. We were asked to create a node.js server that can respond to GET requests, designed around a theoretical connected device. We were also asked to look into network settings videos as well as to connect an Arduino Nano our WiFi network, and show its signal strength on a display as we moved the Nano around.

Disclaimer

To be honest, entering this assignment, I was lost at the idea of what a server was, but more on that in a bit… I realize that, having grown up around technology–and even selling it as my first job out of college (to places like NYU, in fact!), my understanding of what/how parts of technology may be way-off, out-dated, or both. To me a server is a box… but I know there are virtual servers, so I figured I would go through all the material and see how that shaded my understanding. After reading, watching a few videos, and rewatching most of this week’s Zoom lecture, I decided to dive in. As theoretical and practical can be wildly different, I figured I’d trying poking around further to change my grasp on the material.

Diving In

As I’ve had a hosting package and domains for over a decade, I decided to start by playing around with what we looked at in class and ssh-ing into my hosting package. It was interesting–so many more layers of files that you can get to using my normal FTP login. One thing I thought was interesting (and made sense) was that I was not allowed to force commands by using ‘sudo’–it said it did not understand the ‘sudo’ command. (Probably a good thing.)

I also tried ssh-ing into my Raspberry Pi 4 that I purchased to use on projects. I was able to, but didn’t poke around too much as I didn’t have much on it and was planning on reformatting it. Unfortunately, in doing that, I believe I somehow led my Mac to believe that the Raspberry Pi was at one address… then when I reformatted the Raspberry Pi to follow a process that would make it more secure, I got an error message from my terminal saying that it appeared there was a ECDSA issue/possible man-in-the-middle attack.

Example of ECDSA message in terminal. I saw something like this. (Source - Arthur Roncey, Medium)
Example of ECDSA message in terminal. I saw something like this. (Source – Arthur Roncey, Medium)

I detached my Pi from my Mac and attached it to an HDMI display. Interestingly, the username on the Pi I logged into had the wifi username and password information (as I’d entered it and uploaded it to a special wpa config file); however, the device wouldn’t allow me to connect via WiFi saying “eth0: Link is down” and “wlan0: Not associated”. It’s not a big deal; I can start over again, I’m sure and just connect directly to a display, but I definitely see the benefit in setting it up more securely.

I decided to set the Raspberry Pi aside and focus more on the examples provided. I was able to get some to work, but others, eh,notsomuch. I was pretty proud(? ok, maybe an overstatement, but I was hitting a lot of walls) of myself when I realized the error message I had been getting when trying to run one of these examples was happening because I had MAMP (an Apache web server for use on MacOS) running in the background (and using the port.) I tested the code to see if simply changing from port 8080 (where MAMP was using to communicate) to port 8082 in the code–it worked. Two servers running at once on my machine!

Playing Around with the Code Examples Given. I had a problem at first because port 8080 was in use--thanks, Apache! I tried changing to port 8082 and it worked!
Playing Around with the Code Examples Given. I had a problem at first because port 8080 was in use–thanks, Apache! I tried changing to port 8082 and it worked!

As I looked into the examples of setting up a node.js server, I became overwhelmed… not fully understanding what is desired from “creating a server” (I guessed it was a file system, but then how is a server ‘running’ if it’s just files… so does it need more.) I didn’t understand why different files were just .js and others called on .html. “What’s the difference? What’s the bare minimum for something to be considered a server… and what else is typically included?”, I asked myself.

I had a ton of questions, so I took up my professor on his offer to email him with any questions. (Thanks, Tom, for all your patience and feedback with all my projects!)

Trying not to drown

After hearing back from Tom, I read through a few other suggested pages on Node.js, REST, and even a bit from previous weeks on the subject of HTTP/URLs. Reading about dev stuff is tedious. I rarely understand a bunch of jargon-y words describing something I know little about… frankly, even for stuff I know quite a bit about, dev pages are rough. I definitely appreciated the direct links to the info. Eventually, I watched a couple videos I found on YouTube that I felt helped, but I still really don’t feel super confident in the subject. It’s incredible the time you can spend trying to eke out what you need from the internet and still…

Screen Shot of My VERY First Time Creating a Folder, File, Writing the Code, and Running it ALL in Terminal! Very Great Feeling!
SUCCESS! Screen Shot of My VERY First Time Creating a Folder, File, Writing the Code, and Running it ALL in Terminal! Very Great Feeling! All those tutorials and follow-alongs are sticking!

For example, I don’t understand how much of the code we’re using for Node.js is ‘essential’–specifically, I mean necessary and should just be copied and pasted every time, as it will always be the same. (I understand the value of going through it to make sure you understand what’s going on… but what’s barebones for a basic GET/POST server every time?)

Also, if you’re posting in Node.js, where does it go? I ask this because in the Glitch example we were provided, we were given a page with a slider to change the ‘temperature.’ I downloaded the files and got it to work on my computer. (I really wasn’t sure what to expect.) I saw in the Terminal window where I had to navigate to the localhost port provided. I did so and when I changed the temperature, I expected to see a change in the URL to correspond to some sort of change in the temperature. I didn’t see that.

Screen Shot of Me Serving Up the tigon-get-post Glitch - I had to change to port 55303
Screen Shot of Me Serving Up the tigon-get-post Glitch – I had to change to port 55303. You can see that I also had to install Express.

I also realize that the information was posted to the html page and the json was converted into text, but I don’t completely see the point of having the server involved. (It almost seems like Node is basically serving up the ‘public’ folder, but I don’ t see the whole point of GET/POST.) I definitely don’t think it’s pointless, but just don’t see the point is all. I know it’s ‘fast’ from the videos/readings and that it’s not a file system (from Tom’s email…) I know it’s a ‘runtime engine’ and that Express is a ‘framework’, but context is so important and I feel like I’d have more of a connection to this if I understood better what words like those meant to me for the scope of these projects.

For me, the ability to create APIs is super interesting. I’d love to learn more about that as a way of storing and serving up information. The idea of REST seems to make sense to me, but I don’t feel I’ve seen it in action (maybe more like see the wheels in action) in the examples I’ve been able to get to work from class. Maybe I’m misunderstanding that as well. I’m looking forward to going over examples in class.

Jumping right back in…

So, I reviewed the ArduinoHttpClient Venmo video again from this week and decided to give the code a go. I downloaded the repository for Making Things Talk and uploaded the sketches for TestHttpClient.ino and TestHttpSSHClient.ino. (both under the 3rd edition > chapter 4.)

Screen Shot of my Practicing with TestHTTPClient : TestHttpSSLClient. Here is showing the TestHttpSSLClient. I tried entering my domain: https://www.MARTINsquared.com and noticed it was hanging. I tried again, taking out the 'www' and it worked. (Giving me a 301 error.) When I tried adding the 'www' back in, it returned to hanging. Not sure why.

Screen Shot of my Practicing with TestHTTPClient : TestHttpSSLClient. Here is showing the TestHttpSSLClient. I tried entering my domain: https://www.MARTINsquared.com and noticed it was hanging. I tried again, taking out the ‘www’ and it worked. (Giving me a 301 error.) When I tried adding the ‘www’ back in, it returned to hanging. Not sure why.

WiFi Network Signal Strength Reader

WiFi Signal Strength. Display changes as you move the Arduino which is connected to my home WiFi network
WiFi Signal Strength. Display changes as you move the Arduino which is connected to my home WiFi network.

I moved on to the last part of the assignment, thinking I could draw on my knowledge from past projects to put together the reader. I had a strange thing happen when I tried using the WiFi_Reconnect.ino example. I kept getting errors that I didn’t have WiFiNINA.h… I went to the Library Manager and tried installing the WiFiNINA library (screen shot below), but when I’d run the sketch it said WiFiNINA was missing, so I did the “WiFi 101 / WiFiNINA Updater” under Tools (by uploading the updater sketch to my Nano) then tried installing WiFiNINA from the Library Manager again, but it kept showing me the option to Install after I’ve clicked install (and after showing the install progress bar below.)

Following my professor’s advice, I downloaded the WiFiNINA library from the Arduino libraries repo. I saw that the WiFiNINA library was there along with a library called WiFiNINA_Generic, so I uploaded the zip and now “WiFiNINA-master” appears in the Arduino libraries in my finder AND WiFiNINA also appears as an option now.

That said, I was able to keep moving earlier using the WiFiNINA_Generic library for the sketch. You can see the code in my repo. If you choose to use the repo, please be aware that not only does it show WiFiNINA_Generic as selected, but there is also a second tab called “arduino_secrets.h”.

Here is the link to my GitHub repo for WiFi Reconnect with Scanner using an OLED display for showing signal strengths.

I used the same configuration that is listed on the examples page for the OLED screens.

My Breadboard for my WiFi Network Signal Strength Reader
My Breadboard for my WiFi Network Signal Strength Reader