mirror of
https://github.com/NolanMascrier/arduino.git
synced 2025-10-29 15:15:59 +00:00
Preparing for server sending
This commit is contained in:
parent
7d9285e6da
commit
e9dc6c38ee
0
.gitignore
vendored
Normal file
0
.gitignore
vendored
Normal file
@ -42,8 +42,8 @@ int status = STATUS_SAFE;
|
||||
int ledState = LOW;
|
||||
|
||||
//please enter your sensitive data in the Secret tab
|
||||
char ssid[] = SECRET_SSID; // your network SSID (name)
|
||||
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
|
||||
//char ssid[] = SECRET_SSID; // your network SSID (name)
|
||||
//char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
|
||||
|
||||
unsigned long previousMillis = 0;
|
||||
|
||||
@ -56,6 +56,9 @@ const long intervalShort = 20;
|
||||
const int trigger = 12;
|
||||
const int echo = 11;
|
||||
|
||||
//std::string sides[6];
|
||||
std::string sides[6] = {"Bottom", "Top", "Right", "Front", "Left", "Back"};
|
||||
|
||||
int count = 0;
|
||||
|
||||
long duration = 0;
|
||||
@ -95,19 +98,19 @@ void setup() {
|
||||
*
|
||||
* @return calculated distance.
|
||||
*/
|
||||
long fire_sensor(int trigger, int echo)
|
||||
int fire_sensor(int trigger, int echo)
|
||||
{
|
||||
long dist;
|
||||
int dist;
|
||||
long dur;
|
||||
|
||||
digitalWrite(trigger, LOW);
|
||||
delayMicroseconds(2);
|
||||
delayMicroseconds(100);
|
||||
digitalWrite(trigger, HIGH);
|
||||
delayMicroseconds(10);
|
||||
delayMicroseconds(500);
|
||||
digitalWrite(trigger, LOW);
|
||||
dur = pulseIn(echo, HIGH);
|
||||
dist = dur * 0.034 / 2;
|
||||
delay(50);
|
||||
delay(100);
|
||||
return (dist);
|
||||
}
|
||||
|
||||
@ -126,7 +129,7 @@ void loop() {
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
Serial.print("Sensor {");
|
||||
Serial.print(i);
|
||||
Serial.print(sides[i].c_str());
|
||||
Serial.print("} : ");
|
||||
Serial.print(distances[i]);
|
||||
Serial.println("cm");
|
||||
@ -134,6 +137,6 @@ void loop() {
|
||||
//update_status(distance);
|
||||
|
||||
// wait a bit before reading again
|
||||
delayMicroseconds(1000000);
|
||||
delayMicroseconds(10000);
|
||||
count++;
|
||||
}
|
||||
|
||||
5
ArduinoCube/arduino_secrets.h
Normal file
5
ArduinoCube/arduino_secrets.h
Normal file
@ -0,0 +1,5 @@
|
||||
#define SSID "Non"
|
||||
#define PASS "Non"
|
||||
#define SERV_ADDR "Non"
|
||||
#define SERV_PORT "Non"
|
||||
#define AI_KEY "Non"
|
||||
57
server.py
Normal file
57
server.py
Normal file
@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
License: MIT License
|
||||
Copyright (c) 2023 Miel Donkers
|
||||
|
||||
Very simple HTTP server in python for logging requests
|
||||
Usage::
|
||||
./server.py [<port>]
|
||||
"""
|
||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||
import logging
|
||||
import json
|
||||
|
||||
class S(BaseHTTPRequestHandler):
|
||||
def _set_response(self):
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', 'text/html')
|
||||
self.end_headers()
|
||||
|
||||
def do_GET(self):
|
||||
logging.info("GET request,\nPath: %s\nHeaders:\n%s\n", str(self.path), str(self.headers))
|
||||
self._set_response()
|
||||
self.wfile.write("GET request for {}".format(self.path).encode('utf-8'))
|
||||
|
||||
def do_POST(self):
|
||||
content_length = int(self.headers['Content-Length'])
|
||||
post_data = self.rfile.read(content_length)
|
||||
|
||||
# Parse JSON
|
||||
try:
|
||||
data = json.loads(post_data.decode('utf-8'))
|
||||
logging.info("Received data: %s", data)
|
||||
except json.JSONDecodeError:
|
||||
logging.error("Failed to decode JSON")
|
||||
|
||||
self._set_response()
|
||||
self.wfile.write("Received JSON data".encode('utf-8'))
|
||||
|
||||
def run(server_class=HTTPServer, handler_class=S, port=8080):
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
server_address = ('', port)
|
||||
httpd = server_class(server_address, handler_class)
|
||||
logging.info('Starting httpd...\n')
|
||||
try:
|
||||
httpd.serve_forever()
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
httpd.server_close()
|
||||
logging.info('Stopping httpd...\n')
|
||||
|
||||
if __name__ == '__main__':
|
||||
from sys import argv
|
||||
|
||||
if len(argv) == 2:
|
||||
run(port=int(argv[1]))
|
||||
else:
|
||||
run()
|
||||
Loading…
Reference in New Issue
Block a user