Skip to content
TeeKaa OpSec AB Blog

TeeKaa OpSec AB Blog

Side Projects, tutorials, howtos and notes

  • Blog Home
  • Privacy Policy
  • About this blog
  • Back to Main Site
  • Toggle search form

Blink

Posted on 2022-11-262023-02-02 By Teekåå

//// Parody on the first goal whenever messing with embedded systems, get a led to blink, example from wemos D1 Mini ESP12F 4mb ////

With a Twist, The blink should be manually performed. Via a web server on the unit. Web server the size of a thumbnail. What a time to be alive.

Below code is from a private repository shared between me and a friend 🙂

main.cpp

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266mDNS.h>
#include <ESP8266WebServer.h> // Include the WebServer library
#include “secret.h” //include WIFI SSID and PW

ESP8266WiFiMulti wifiMulti; // Create an instance of the ESP8266WiFiMulti class, called ‘wifiMulti’
ESP8266WebServer server(80); // Create a webserver object that listens for HTTP request on port 80
const int led = 2;
void handleLED();

void setup(void){
Serial.begin(9600); // Start the Serial communication to send messages to the computer
delay(10);
Serial.println(‘\n’);
pinMode(led, OUTPUT);
WiFi.begin(SSID_NAME, WIFIPASS); // Connect to the network
Serial.print(“Connecting to “);
Serial.print(SSID_NAME);
Serial.println(‘ ‘);

int i = 0;
while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
delay(1000);
Serial.print(“…”);
i++;
}

Serial.println(‘ ‘);
Serial.print(“Took “);
Serial.print(i);
Serial.print(” seconds to connect and receive response from DHCP.”);

Serial.println(‘\n’);
Serial.print(“Connected to “);
Serial.println(WiFi.SSID()); // Tell us what network we’re connected to
Serial.print(“IP address:\t”);
Serial.println(WiFi.localIP()); // Send the IP address of the ESP8266 to the computer
MDNS.notifyAPChange();
delay(1000);
if (MDNS.begin(“esp8266”)) { // Start the mDNS responder for esp8266.local
Serial.println(“mDNS responder started”);
} else {
Serial.println(“Error setting up MDNS responder!”);
}
server.on(“/”, HTTP_GET, handleRoot); // Call the ‘handleRoot’ function when a client requests URI “/”
server.on(“/LED”, HTTP_POST, handleLED); // Call the ‘handleLED’ function when a POST request is made to URI “/LED”
server.begin(); // Actually start the server
Serial.println(“HTTP server started”);
}
void loop(void){
server.handleClient(); // Listen for HTTP requests from clients
MDNS.update();
}

void handleRoot() { // When URI / is requested, send a web page with a button to toggle the LED

server.send(200, “text/html”, “<form action=\”/LED\” method=\”POST\”><input type=\”submit\” value=\”Toggle LED\”> </form> <br> <br> <form action=\”/DIST\” method=\”POST\”><input type=\”submit\” value=\”Measure distance\”></form>”);

}
void handleLED() { // If a POST request is made to URI /LED
digitalWrite(led,!digitalRead(led)); // Change the state of the LED
server.sendHeader(“Location”,”/”);
server.send(303); // Send it back to the browser with an HTTP status 303 (See Other) to redirect
}

Related

Offtopic or noncategorizable

Post navigation

Previous Post: Hello world!
Next Post: A Hardware Hacker’s (or Penetration Tester’s) must haves

Related Posts

Hello world! Offtopic or noncategorizable

Archives

  • February 2023
  • January 2023
  • December 2022
  • November 2022

Categories

  • Educational content
  • Hardware hacking 101
  • Informative Rants
  • Offtopic or noncategorizable
  • Warnings and newsflash

Recent Posts

  • Secure C programming practices (or HowToMake C Memory Safe(r))
  • Breaking news! Update every device you own, Qualcomm TrustZone TrustEnvironment is pwned
  • Addition to FISA702 rant about who has access to your living room
  • The Right to Privacy, Data Protection and American legislative FISA702
  • Something to practice on (series): Asus router

Recent Comments

No comments to show.

Copyright © 2023 TeeKaa OpSec AB Blog.

Powered by PressBook Masonry Dark