about me final project 01 02 03 04 05 06 07 08 09 10 11

09: networking/IoT

introduction

This page describes what I have learned with class 9, held on 21 July, 2020. This class dealt with networking and controlling boards through WiFi and other internet connection.


understanding wifi and internet connection

This class focused on understanding how internet works and how we can use it to control boards not in our vicinity through the internet. We discussed LANa and Wifi. More information can be found on Nathan's page linked here. There's a lot to write, and there's a lot I learned, but I believe it's best described with my assignment and the learning process for getting that to work.


breakout rooms: controlling leds with internet

We worked with LEDs and controlling them through the internet. We used FireBase, which allows us to control them from anywhere in the world, even outside the local network. This culminated in configuring FireBase and even controlling these LEDs from a website which had FireBase configured for me. This website most likely doesn't work anymore (as it has probably been a while since I disconnected the circuit from my computer by the time you are viewing this page), but it can still be accessed here. The JS is not mine, as it was used for demonstrative purposes. As always, more documentation on how this works and how to set it up can be found on Nathan's GitHub page, as well as the subsequent links for Rob's pages; just remember to input your own personal data there when it comes to configuring FireBase.


assignment

For the assignment, we practiced controlling a different device through the internet. I decided to replace the LED with a buzzer, to see if I could make the buzzer make a noise.

working with the buzzer

Here, I detail what I did with the buzzer, code and videos included.


the circuit

For the simplest of circuits, I simply decided to replace the LED with the buzzer. However, since the pins didn't align because of the sizes, I wired it a little further. This was meant to resemble Rob's alternate wiring for the LED shown in a Slack channel, and I simply swapped out the LED for a buzzer. The circuit is visible here.

buzzer circuit

the code

The code was a very simple modification on the code we used in the tutorials for the LED, found on Nathan's page. I simply made it produce a tone instead of turning the LED on. Of course, it is important to include a definition of the myTone() function here, as I am using the Huzzah.

                
                  #include                                                    // esp32 library
                  #include                                           // firebase library

                  #define FIREBASE_HOST "----"                                      // the project name address from firebase id -- SECRET FOR PRIVACY REASONS
                  #define FIREBASE_AUTH "----"                                      // the secret key generated from firebase -- SECRET FOR PRIVACY REASONS
                  #define WIFI_SSID "----"                                          // input your home or public wifi name -- SECRET FOR PRIVACY REASONS
                  #define WIFI_PASSWORD "----"                                      // password of wifi ssid -- SECRET FOR PRIVACY REASONS

                  String fireString = "";                                             // buzzer status received from firebase
                  int buzzerpin = 5;

                  //Define FirebaseESP32 data object
                  FirebaseData firebaseData;

                  void setup() {
                    Serial.begin(9600);
                    delay(1000);
                    pinMode(buzzerpin, OUTPUT);
                    WiFi.begin(WIFI_SSID, WIFI_PASSWORD);                             // try to connect with wifi

                    Serial.print("Connecting to ");
                    Serial.print(WIFI_SSID);
                    while (WiFi.status() != WL_CONNECTED) {
                      Serial.print(".");
                      delay(500);
                    }

                    Serial.println();
                    Serial.print("Connected to ");
                    Serial.println(WIFI_SSID);
                    Serial.print("IP Address is : ");
                    Serial.println(WiFi.localIP());                                   // print local IP address
                    Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);                     // connect to firebase
                    Firebase.reconnectWiFi(true);
                    Firebase.set(firebaseData, "/BUZZER_STATUS", "OFF");              // set initial string of "OFF"
                  }

                  void loop() {

                    Firebase.get(firebaseData, "/BUZZER_STATUS");                     // get buzzwe status input from firebase
                    fireString = firebaseData.stringData();                           // change to e.g. intData() or boolData()
                    Serial.println(fireString);

                    if (fireString == "ON") {                            // compare the input of buzzer status received from firebase
                      Serial.println("Buzzer has been BUZZED");
                      myTone(buzzerpin, 1397, 1000);                     // buzz buzzer repeatedly
                      delay(1000);
                    }

                    else if (fireString == "OFF") {                      // compare the input of buzzer status received from firebase
                      Serial.println("Buzzer no longer BUZZING");
                    }

                    else {
                      Serial.println("Please send ON/OFF");
                    }

                    delay(1000);                                        // not strictly necessary
                  }

                  // define myTone() function for those using Huzzah or other ESP32 boards
                  void myTone(int pin, int frequency, int duration){
                    int startTime = millis();
                    int period = 1000000/frequency;
                    while ((millis() - startTime) < duration){
                      digitalWrite(pin, HIGH);
                      delayMicroseconds(period/2);
                      digitalWrite(pin, LOW);
                      delayMicroseconds(period/2);
                    }
                  }
                
              

the results

I currently was not able to get the website configured, but I can change the status from the FireBase project page, as is visible in the video here. The embedded video is also down below, but the link is available in case the embedded player does not work.



I eventually got the site configured, which can be accessed below with the link I provided. It took me a while to see exactly what I did wrong, but I got this configured in the end.


Overall, I learned a lot about controlling things through the internet, which is pretty cool! The link for further documentation on JavaScript and another cool place where you can toggle my buzzer from your home is here, though it probably long doesn't work by the time you push those buttons.


final project thoughts

I am not sure if I plan on using this for my final project, but it is certainly a cool idea. I am now able to control things from other sides of the planet, which I think is fairly awesome.


An overall productive week, I was ready to completely immerse myself in my final project. Until the next class!


final message: 10 august, 2020

As of 10 August, 2020 (the publishing of this final bit), all documentation of this website has been finalized, and no further documentation will be added to this website. No additional photos, videos, code snippets, models, or commentary will be posted to this site. This website is meant to serve as the documentation of my learning during the Introduction to Digital Fabrication (PHYS S-12) course during Harvard Summer School 2020, and the program officially ended on 10 August. Thus, this website will no longer be edited and nothing will be added to it. This is why my biographical information may no longer be accurate at the time of reading of this page. It has been a fun run, but sadly, the course is over, and thus my documentation is also complete. Thank you to anyone and everyone who helped me along the way, and I am excited for future endeavors!