@@ -0,0 +1,20 @@ | |||
import os | |||
# https://stackoverflow.com/questions/49449430/python-bytes-to-c-array-like-xxd-program/49450004 | |||
def bytes_to_c_arr(data, lowercase=True): | |||
return [format(b, '#04x' if lowercase else '#04X') for b in data] | |||
src = 'include/http' | |||
out = 'include' | |||
for f in os.listdir(src): | |||
with open(f'{src}/{f}', 'rb') as f_in: | |||
with open(f'{out}/{f}.h', 'wb') as f_out: | |||
buf = 'const char {}[] = {{{}}};'.format( | |||
f.replace('.', '_'), | |||
', '.join(bytes_to_c_arr(f_in.read())) | |||
) | |||
f_out.write(buf.encode(encoding='ascii')) | |||
@@ -1,39 +0,0 @@ | |||
This directory is intended for project header files. | |||
A header file is a file containing C declarations and macro definitions | |||
to be shared between several project source files. You request the use of a | |||
header file in your project source file (C, C++, etc) located in `src` folder | |||
by including it, with the C preprocessing directive `#include'. | |||
```src/main.c | |||
#include "header.h" | |||
int main (void) | |||
{ | |||
... | |||
} | |||
``` | |||
Including a header file produces the same results as copying the header file | |||
into each source file that needs it. Such copying would be time-consuming | |||
and error-prone. With a header file, the related declarations appear | |||
in only one place. If they need to be changed, they can be changed in one | |||
place, and programs that include the header file will automatically use the | |||
new version when next recompiled. The header file eliminates the labor of | |||
finding and changing all the copies as well as the risk that a failure to | |||
find one copy will result in inconsistencies within a program. | |||
In C, the usual convention is to give header files names that end with `.h'. | |||
It is most portable to use only letters, digits, dashes, and underscores in | |||
header file names, and at most one dot. | |||
Read more about using header files in official GCC documentation: | |||
* Include Syntax | |||
* Include Operation | |||
* Once-Only Headers | |||
* Computed Includes | |||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html |
@@ -0,0 +1,19 @@ | |||
<html> | |||
<head> | |||
<meta http-equiv='refresh' content='5' /> | |||
<title>ESP8266 Demo</title> | |||
<style> | |||
body { | |||
background-color: #cccccc; | |||
font-family: Arial, Helvetica, Sans-Serif; | |||
Color: #000088; | |||
} | |||
</style> | |||
</head> | |||
<body> | |||
<h1>Hello from ESP8266!</h1> | |||
</body> | |||
</html> |
@@ -0,0 +1 @@ | |||
const char index_html[] = {0x3c, 0x68, 0x74, 0x6d, 0x6c, 0x3e, 0x0d, 0x0a, 0x0d, 0x0a, 0x3c, 0x68, 0x65, 0x61, 0x64, 0x3e, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x6d, 0x65, 0x74, 0x61, 0x20, 0x68, 0x74, 0x74, 0x70, 0x2d, 0x65, 0x71, 0x75, 0x69, 0x76, 0x3d, 0x27, 0x72, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x27, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x3d, 0x27, 0x35, 0x27, 0x20, 0x2f, 0x3e, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x3e, 0x45, 0x53, 0x50, 0x38, 0x32, 0x36, 0x36, 0x20, 0x44, 0x65, 0x6d, 0x6f, 0x3c, 0x2f, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x3e, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x73, 0x74, 0x79, 0x6c, 0x65, 0x3e, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x7b, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x62, 0x61, 0x63, 0x6b, 0x67, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x2d, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x3a, 0x20, 0x23, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x3b, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6f, 0x6e, 0x74, 0x2d, 0x66, 0x61, 0x6d, 0x69, 0x6c, 0x79, 0x3a, 0x20, 0x41, 0x72, 0x69, 0x61, 0x6c, 0x2c, 0x20, 0x48, 0x65, 0x6c, 0x76, 0x65, 0x74, 0x69, 0x63, 0x61, 0x2c, 0x20, 0x53, 0x61, 0x6e, 0x73, 0x2d, 0x53, 0x65, 0x72, 0x69, 0x66, 0x3b, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x3a, 0x20, 0x23, 0x30, 0x30, 0x30, 0x30, 0x38, 0x38, 0x3b, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7d, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x2f, 0x73, 0x74, 0x79, 0x6c, 0x65, 0x3e, 0x0d, 0x0a, 0x3c, 0x2f, 0x68, 0x65, 0x61, 0x64, 0x3e, 0x0d, 0x0a, 0x0d, 0x0a, 0x3c, 0x62, 0x6f, 0x64, 0x79, 0x3e, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x3c, 0x68, 0x31, 0x3e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x45, 0x53, 0x50, 0x38, 0x32, 0x36, 0x36, 0x21, 0x3c, 0x2f, 0x68, 0x31, 0x3e, 0x0d, 0x0a, 0x3c, 0x2f, 0x62, 0x6f, 0x64, 0x79, 0x3e, 0x0d, 0x0a, 0x0d, 0x0a, 0x3c, 0x2f, 0x68, 0x74, 0x6d, 0x6c, 0x3e}; |
@@ -14,10 +14,12 @@ board = esp01_1m | |||
framework = arduino | |||
monitor_speed = 115200 | |||
extra_scripts = pre:extra_script.py | |||
; stuff for OTA | |||
; https://docs.platformio.org/en/latest/platforms/espressif8266.html#over-the-air-ota-update | |||
upload_protocol = espota | |||
upload_port = 192.168.178.75 | |||
upload_port = 192.168.10.94 | |||
upload_flags = | |||
--port=8266 | |||
--auth=admin |
@@ -1,4 +1,7 @@ | |||
#include <Arduino.h> | |||
#include <Wire.h> | |||
#include "PCA9685.h" | |||
#include <ESP8266WiFi.h> | |||
#include <ESP8266mDNS.h> | |||
@@ -11,6 +14,8 @@ | |||
#include "wifi_credentials.h" | |||
#include "index.html.h" | |||
const char* ssid = STASSID; | |||
const char* password = STAPSK; | |||
@@ -19,31 +24,10 @@ ESP8266WebServer server(80); | |||
void handleRoot() { | |||
digitalWrite(led, 1); | |||
char temp[400]; | |||
int sec = millis() / 1000; | |||
int min = sec / 60; | |||
int hr = min / 60; | |||
snprintf(temp, 400, | |||
"<html>\ | |||
<head>\ | |||
<meta http-equiv='refresh' content='5'/>\ | |||
<title>ESP8266 Demo</title>\ | |||
<style>\ | |||
body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\ | |||
</style>\ | |||
</head>\ | |||
<body>\ | |||
<h1>Hello from ESP8266!</h1>\ | |||
<p>Uptime: %02d:%02d:%02d</p>\ | |||
<img src=\"/test.svg\" />\ | |||
</body>\ | |||
</html>", | |||
hr, min % 60, sec % 60 | |||
); | |||
server.send(200, "text/html", temp); | |||
// char temp[sizeof(index_html)]; | |||
// snprintf(temp, sizeof(index_html), index_html); | |||
server.send(200, "text/html", index_html); | |||
digitalWrite(led, 0); | |||
} | |||
@@ -161,8 +145,9 @@ void setup() { | |||
} | |||
unsigned long i = 0; | |||
unsigned long i = 0; | |||
unsigned long a = 0; | |||
unsigned long s = 0; | |||
float ard_ota_time = 0; |
@@ -1,11 +0,0 @@ | |||
This directory is intended for PlatformIO Unit Testing and project tests. | |||
Unit Testing is a software testing method by which individual units of | |||
source code, sets of one or more MCU program modules together with associated | |||
control data, usage procedures, and operating procedures, are tested to | |||
determine whether they are fit for use. Unit testing finds problems early | |||
in the development cycle. | |||
More information about PlatformIO Unit Testing: | |||
- https://docs.platformio.org/page/plus/unit-testing.html |