ME507 Airheads Project v1.1.0
Flight Stabilization for Glider
Loading...
Searching...
No Matches
network.cpp File Reference

This program runs a very simple web server, demonstrating how to serve a static web page and how to use a web link to get the microcontroller to do something simple. More...

#include <Arduino.h>
#include "PrintStream.h"
#include <WiFi.h>
#include <WebServer.h>
#include <shares.h>
#include <taskshare.h>

Functions

Share< bool > web_calibrate ("Flag to calibrate/zero")
 A share containing a boolean flagging the main script to zero the potentiometers.
 
IPAddress local_ip (192, 168, 5, 1)
 Address of ESP32 on its own network.
 
IPAddress gateway (192, 168, 5, 1)
 The ESP32 acts as its own gateway.
 
IPAddress subnet (255, 255, 255, 0)
 Network mask; just leave this as is.
 
WebServer server (80)
 The web server object for this project. More...
 
void setup_wifi (void)
 Get the WiFi running so we can serve some web pages. More...
 
void HTML_header (String &a_string, const char *page_title)
 Put a web page header into an HTML string. More...
 
void handle_DocumentRoot ()
 Callback function that responds to HTTP requests without a subpage name. More...
 
void handle_NotFound (void)
 Respond to a request for an HTTP page that doesn't exist. More...
 
void handle_Activate (void)
 Switches the state in a FSM when called by the web server. More...
 
void handle_Deactivate (void)
 Switches the state in a FSM when called by the web server. More...
 
void handle_Calibrate (void)
 Switches the state in a FSM when called by the web server. More...
 
void task_webserver (void *p_params)
 Task which sets up and runs a web server. More...
 

Variables

const char * ssid = "AirHeads 507"
 SSID, network name seen on LAN lists.
 
const char * password = "??what??"
 ESP32 WiFi password (min. 8 characters)
 

Detailed Description

This program runs a very simple web server, demonstrating how to serve a static web page and how to use a web link to get the microcontroller to do something simple.

Based on an examples by A. Sinha at https://github.com/hippyaki/WebServers-on-ESP32-Codes

Author
A. Sinha
JR Ridgely
Damond Li
Date
2022-Mar-28 Original stuff by Sinha
2022-Nov-04 Modified for ME507 use by Ridgely
2022-Nov-29 Modified for Airheads Glider Project use by Li

Function Documentation

◆ handle_Activate()

void handle_Activate ( void  )

Switches the state in a FSM when called by the web server.

This method alters a shared variable that contains the current state of a FSM in the controller task located in main.cpp. The state is switched to 1.

◆ handle_Calibrate()

void handle_Calibrate ( void  )

Switches the state in a FSM when called by the web server.

This method alters a shared variable that contains the current state of a FSM in the controller task located in main.cpp. The state is switched to 1 and a calibrate boolean is set to true whic will be handled in the controller task.

◆ handle_Deactivate()

void handle_Deactivate ( void  )

Switches the state in a FSM when called by the web server.

This method alters a shared variable that contains the current state of a FSM in the controller task located in main.cpp. The state is switched to 0.

◆ handle_DocumentRoot()

void handle_DocumentRoot ( )

Callback function that responds to HTTP requests without a subpage name.

When another computer contacts this ESP32 through TCP/IP port 80 (the insecure Web port) with a request for the main web page, this callback function is run. It sends the main web page's text to the requesting machine.

◆ handle_NotFound()

void handle_NotFound ( void  )

Respond to a request for an HTTP page that doesn't exist.

This function produces the Error 404, Page Not Found error.

◆ HTML_header()

void HTML_header ( String &  a_string,
const char *  page_title 
)

Put a web page header into an HTML string.

This header may be modified if the developer wants some actual style for her or his web page. It is intended to be a common header (and stylle) for each of the pages served by this server.

Parameters
a_stringA reference to a string to which the header is added; the string must have been created in each function that calls this one
page_titleThe title of the page

◆ server()

WebServer server ( 80  )

The web server object for this project.

This server is responsible for responding to HTTP requests from other computers, replying with useful information.

It's kind of clumsy to have this object as a global, but that's the way Arduino keeps things simple to program, without the user having to write custom classes or other intermediate-level structures.

◆ setup_wifi()

void setup_wifi ( void  )

Get the WiFi running so we can serve some web pages.

Function used to setup the wifi on the ESP32.

◆ task_webserver()

void task_webserver ( void *  p_params)

Task which sets up and runs a web server.

The webpage task that runs the webpage on the ESP32.

After setup, function handleClient() must be run periodically to check for page requests from web clients. One could run this task as the lowest priority task with a short or no delay, as there generally isn't much rush in replying to web queries.

Parameters
p_paramsPointer to unused parameters