Skip to content

Commit 59991e8

Browse files
committed
Initial Upload
0 parents  commit 59991e8

File tree

435 files changed

+42241
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

435 files changed

+42241
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.pio
2+
.vscode/.browse.c_cpp.db*
3+
.vscode/c_cpp_properties.json
4+
.vscode/launch.json
5+
.vscode/ipch

.travis.yml

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Continuous Integration (CI) is the practice, in software
2+
# engineering, of merging all developer working copies with a shared mainline
3+
# several times a day < https://docs.platformio.org/page/ci/index.html >
4+
#
5+
# Documentation:
6+
#
7+
# * Travis CI Embedded Builds with PlatformIO
8+
# < https://docs.travis-ci.com/user/integration/platformio/ >
9+
#
10+
# * PlatformIO integration with Travis CI
11+
# < https://docs.platformio.org/page/ci/travis.html >
12+
#
13+
# * User Guide for `platformio ci` command
14+
# < https://docs.platformio.org/page/userguide/cmd_ci.html >
15+
#
16+
#
17+
# Please choose one of the following templates (proposed below) and uncomment
18+
# it (remove "# " before each line) or use own configuration according to the
19+
# Travis CI documentation (see above).
20+
#
21+
22+
23+
#
24+
# Template #1: General project. Test it using existing `platformio.ini`.
25+
#
26+
27+
# language: python
28+
# python:
29+
# - "2.7"
30+
#
31+
# sudo: false
32+
# cache:
33+
# directories:
34+
# - "~/.platformio"
35+
#
36+
# install:
37+
# - pip install -U platformio
38+
# - platformio update
39+
#
40+
# script:
41+
# - platformio run
42+
43+
44+
#
45+
# Template #2: The project is intended to be used as a library with examples.
46+
#
47+
48+
# language: python
49+
# python:
50+
# - "2.7"
51+
#
52+
# sudo: false
53+
# cache:
54+
# directories:
55+
# - "~/.platformio"
56+
#
57+
# env:
58+
# - PLATFORMIO_CI_SRC=path/to/test/file.c
59+
# - PLATFORMIO_CI_SRC=examples/file.ino
60+
# - PLATFORMIO_CI_SRC=path/to/test/directory
61+
#
62+
# install:
63+
# - pip install -U platformio
64+
# - platformio update
65+
#
66+
# script:
67+
# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N

.vscode/extensions.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
// See http://go.microsoft.com/fwlink/?LinkId=827846
3+
// for the documentation about the extensions.json format
4+
"recommendations": [
5+
"platformio.platformio-ide"
6+
]
7+
}

C232HM.cfg

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# FTDI USB Hi-Speed to MPSSE Cable
3+
#
4+
# http://www.ftdichip.com/Products/Cables/USBMPSSE.htm
5+
#
6+
# C232HM-DDHSL-0 and C232HM-EDSL-0 provide 3.3V and 5V on pin 1 (Red),
7+
# respectively.
8+
#
9+
10+
#interface ftdi
11+
#ftdi_device_desc "C232HM-DDHSL-0"
12+
#ftdi_device_desc "C232HM-EDHSL-0"
13+
#ftdi_vid_pid 0x0403 0x6014
14+
15+
#ftdi_layout_init 0x0008 0x000b
16+
17+
interface ft232r
18+
adapter_khz 26000
19+
ft232r_vid_pid 0x0403 0x6001

CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cmake_minimum_required(VERSION 3.16.0)
2+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
3+
project(Webpage_Testing)

In_Progress/SBHttp_Server.cpp

+219
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
/* Async Webpage server */
2+
3+
#include <SBHttp_Server.h>
4+
//#include <HTTP_Server_Basic.h>
5+
#include <smartbike_parameters.h>
6+
#include <Main.h>
7+
8+
// Import required libraries
9+
#include <Arduino.h>
10+
#include <WiFi.h>
11+
#include <WiFiAP.h>
12+
#include <ESPAsyncWebServer.h>
13+
#include <AsyncTCP.h>
14+
#include <SPIFFS.h>
15+
#include <FS.h>
16+
#include <string.h>
17+
#define MAX_BUFFER_SIZE 20
18+
19+
// Set LED GPIO
20+
const int ledPin = 2; //Blue LED on the ESP32
21+
// Stores LED state
22+
String ledState;
23+
// Webpage Parameter varables
24+
const char* webStringParameter = "state";
25+
const char* webIntParameter = "value";
26+
int i; //Multi use integer for general purpose
27+
28+
/********************Added Function for SPIFFS File Testing*****************************/
29+
void printFile(String filename) {
30+
// Open file for reading
31+
Serial.printf("Contents of file: %s/n", filename.c_str());
32+
File file = SPIFFS.open(filename);
33+
if (!file) {
34+
Serial.println(F("Failed to read file"));
35+
return;
36+
}
37+
38+
// Extract each characters by one by one
39+
while (file.available()) {
40+
Serial.print((char)file.read());
41+
}
42+
Serial.println();
43+
44+
// Close the file
45+
file.close();
46+
}
47+
48+
/***************************************************************************************/
49+
// Create AsyncWebServer object on port 80
50+
AsyncWebServer server(80);
51+
52+
// Replaces placeholder with LED state value
53+
String processor(const String& var){
54+
char outString[MAX_BUFFER_SIZE];
55+
Serial.printf("Processing Variable from HTTP Server: %s \n", var.c_str());
56+
57+
if(var == "STATE"){
58+
if(digitalRead(ledPin)){
59+
ledState = "ON";
60+
}
61+
else{
62+
ledState = "OFF";
63+
}
64+
Serial.printf("LED State is %s \n", ledState.c_str());
65+
return ledState;
66+
}
67+
68+
if(var =="HROUTPUT"){
69+
if(config.getSimulateHr()){return "checked";}
70+
else{return "";}
71+
}
72+
73+
if(var =="WATTSOUTPUT"){
74+
if(config.getSimulatePower()){return "checked";}
75+
else{return "";}
76+
}
77+
78+
if(var =="HRVALUE"){
79+
snprintf(outString, MAX_BUFFER_SIZE, "%d", config.getSimulatedHr());
80+
strncat(outString, " BPM", 4);
81+
//Serial.printf("outString: %s \n", outString);
82+
return outString;
83+
}
84+
85+
if(var =="WATTSVALUE"){
86+
snprintf(outString, MAX_BUFFER_SIZE, "%d", config.getSimulatedWatts());
87+
strncat(outString, " Watts", 6);
88+
return outString;
89+
}
90+
91+
return String();
92+
}
93+
94+
void startHttpServer(){
95+
96+
pinMode(ledPin, OUTPUT);
97+
98+
// Connect to Wi-Fi
99+
Serial.println();
100+
Serial.println("Configuring access point...");
101+
WiFi.softAP(config.getSsid(), config.getPassword());
102+
vTaskDelay(50);
103+
IPAddress myIP = WiFi.softAPIP();
104+
Serial.print("AP IP address: ");
105+
Serial.println(myIP);
106+
server.begin();
107+
Serial.println("WiFi Server started");
108+
109+
// Route for root / web page
110+
/* I think we need to expand this one server instance to keep from crashing instead of using multiple server.on instances */
111+
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
112+
//request->send(SPIFFS, "/index.html", "text/html");
113+
request->send(SPIFFS, "/index.html", String(), true, processor);
114+
//request->
115+
//request->send(SPIFFS, "/style.css", "text/css");
116+
Serial.println("Index.html Sent");
117+
//printFile("/index.html");
118+
});
119+
120+
// hopefully we can eventually delete all of this below
121+
// Route to load style.css file
122+
server.on("/style.css", HTTP_GET, [](AsyncWebServerRequest *request){
123+
request->send(SPIFFS, "/style.css", "text/css");
124+
Serial.println("/style.css Sent");
125+
printFile("/style.css");
126+
});
127+
// Route to set GPIO to HIGH
128+
server.on("/on", HTTP_GET, [](AsyncWebServerRequest *request){
129+
digitalWrite(ledPin, HIGH);
130+
request->send(SPIFFS, "/index.html", String(), true, processor);
131+
});
132+
133+
// Route to set GPIO to LOW
134+
server.on("/off", HTTP_GET, [](AsyncWebServerRequest *request){
135+
digitalWrite(ledPin, LOW);
136+
request->send(SPIFFS, "/index.html", String(), true, processor);
137+
});
138+
139+
//***************************************Trying to get a value from a range slider
140+
server.on("/hrslider", HTTP_GET, [] (AsyncWebServerRequest *request) {
141+
// GET input1 value on <ESP_IP>/hrslider?value=<inputMessage>
142+
String inputMessage;
143+
if (request->hasParam(webIntParameter)) {
144+
inputMessage = request->getParam(webIntParameter)->value();
145+
config.setSimulatedHr(inputMessage.toInt());
146+
Serial.printf("Heart Rate in Config is %d\n", config.getSimulatedHr());
147+
}
148+
else {
149+
inputMessage = "No message sent";
150+
}
151+
Serial.println(inputMessage);
152+
request->send(SPIFFS, "/index.html", String(), true, processor);
153+
//request->send(200, "text/plain", "OK");
154+
});
155+
156+
server.on("/wattsslider", HTTP_GET, [] (AsyncWebServerRequest *request) {
157+
// GET input1 value on <ESP_IP>/hrslider?value=<inputMessage>
158+
String inputMessage;
159+
if (request->hasParam(webIntParameter)) {
160+
inputMessage = request->getParam(webIntParameter)->value();
161+
config.setSimulatedWatts(inputMessage.toInt());
162+
Serial.printf("Watt in Config is %d\n", config.getSimulatedWatts());
163+
}
164+
else {
165+
inputMessage = "No message sent";
166+
}
167+
Serial.println(inputMessage);
168+
request->send(SPIFFS, "/index.html", String(), true, processor);
169+
//request->send(200, "text/plain", "OK");
170+
});
171+
172+
server.on("/hrenable", HTTP_GET, [] (AsyncWebServerRequest *request) {
173+
// GET input1 value on <ESP_IP>/hrslider?value=<inputMessage>
174+
String inputMessage;
175+
if (request->hasParam(webIntParameter)) {
176+
inputMessage = request->getParam(webIntParameter)->value();
177+
if(inputMessage == "checked"){config.setSimulateHr(true);}
178+
else{config.setSimulateHr(false);}
179+
Serial.printf("HR output is set to %s\n", config.getSimulateHr() ? "On":"Off");
180+
}
181+
else {
182+
inputMessage = "No message sent";
183+
}
184+
Serial.println(inputMessage);
185+
request->send(SPIFFS, "/index.html", String(), true, processor);
186+
//request->send(200, "text/plain", "OK");
187+
});
188+
189+
server.on("/wattsenable", HTTP_GET, [] (AsyncWebServerRequest *request) {
190+
// GET input1 value on <ESP_IP>/hrslider?value=<inputMessage>
191+
String inputMessage;
192+
if (request->hasParam(webIntParameter)) {
193+
inputMessage = request->getParam(webIntParameter)->value();
194+
if(inputMessage == "checked"){config.setSimulatePower(true);}
195+
else{config.setSimulatePower(false);}
196+
Serial.printf("Power output is set to %s\n", config.getSimulatePower() ? "On":"Off");
197+
}
198+
else {
199+
inputMessage = "No message sent";
200+
}
201+
Serial.println(inputMessage);
202+
request->send(SPIFFS, "/index.html", String(), true, processor);
203+
//request->send(200, "text/plain", "OK");
204+
});//
205+
//********************************End Range Slider testing**********************************
206+
// Start server
207+
server.begin();
208+
209+
Serial.println("End of Http setup");
210+
211+
}
212+
/*
213+
void loop(){
214+
//Autosave every 30 seconds
215+
vTaskDelay(30000/portTICK_PERIOD_MS);
216+
Serial.println("Autosaving Configuration");
217+
config.saveToSPIFFS();
218+
config.printFile();
219+
}*/

In_Progress/SBHttp_Server.h

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef SBHTTP_SERVER_H
2+
#define SBHTTP_SERVER_H
3+
//Webserver structures and classes
4+
#include <Arduino.h>
5+
#include <smartbike_parameters.h>
6+
//function Prototypes
7+
8+
/*espidf stuff
9+
#include <stdio.h>
10+
#include <freertos/FreeRTOS.h>
11+
#include <freertos/task.h>
12+
#include "sdkconfig.h"
13+
*/
14+
void startHttpServer();
15+
String processor(const String& var);
16+
17+
#endif

0 commit comments

Comments
 (0)