Adding files
This commit is contained in:
parent
20e85b9085
commit
b609ef5120
2 changed files with 56 additions and 3 deletions
|
@ -1,5 +1,6 @@
|
||||||
#include <ESP32Servo.h>
|
#include <ESP32Servo.h>
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
|
#include <WebServer.h>
|
||||||
|
|
||||||
Servo myservo; // create servo object to control a servo
|
Servo myservo; // create servo object to control a servo
|
||||||
int servoPin = 18;
|
int servoPin = 18;
|
||||||
|
@ -7,6 +8,8 @@ int servoPin = 18;
|
||||||
const char* ssid = "dlink";
|
const char* ssid = "dlink";
|
||||||
const char* password = "";
|
const char* password = "";
|
||||||
|
|
||||||
|
WebServer server(80);
|
||||||
|
|
||||||
void closeCircuitAndOpen(int closeTime=400)
|
void closeCircuitAndOpen(int closeTime=400)
|
||||||
{
|
{
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
@ -22,6 +25,23 @@ void closeCircuitAndOpen(int closeTime=400)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void handleRoot()
|
||||||
|
{ // when accessing server's root
|
||||||
|
String page = "Yeah! I'm not dead! I'm still working ;)";
|
||||||
|
server.send(200, "text/plain", page);
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleNotFound()
|
||||||
|
{ // Page Not found
|
||||||
|
server.send(404, "text/plain","404: Not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
void closeCircuitViaWifi()
|
||||||
|
{
|
||||||
|
closeCircuitAndOpen();
|
||||||
|
server.send(200, "text/plain","Done");
|
||||||
|
}
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
@ -34,7 +54,7 @@ void setup()
|
||||||
myservo.setPeriodHertz(50); // standard 50 hz servo
|
myservo.setPeriodHertz(50); // standard 50 hz servo
|
||||||
myservo.attach(servoPin, 1000, 2000); // attaches the servo on pin 18 to the servo object
|
myservo.attach(servoPin, 1000, 2000); // attaches the servo on pin 18 to the servo object
|
||||||
myservo.write(0);delay(2500); // position to initial suitable position
|
myservo.write(0);delay(2500); // position to initial suitable position
|
||||||
//======WIFI PART======/
|
//======WIFI PART======//
|
||||||
WiFi.mode(WIFI_STA); //Optional
|
WiFi.mode(WIFI_STA); //Optional
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
Serial.println("\nConnecting");
|
Serial.println("\nConnecting");
|
||||||
|
@ -45,11 +65,17 @@ void setup()
|
||||||
Serial.println("\nConnected to the WiFi network");
|
Serial.println("\nConnected to the WiFi network");
|
||||||
Serial.print("Local ESP32 IP: ");
|
Serial.print("Local ESP32 IP: ");
|
||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
|
//======WEB SERVER PART======//
|
||||||
|
server.on("/", handleRoot);
|
||||||
|
server.onNotFound(handleNotFound);
|
||||||
|
server.on("/open", closeCircuitViaWifi);
|
||||||
|
server.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
closeCircuitAndOpen();
|
//closeCircuitAndOpen();
|
||||||
delay(5000);
|
//delay(5000);
|
||||||
|
server.handleClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
27
myapp.py
Normal file
27
myapp.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
import flask
|
||||||
|
import requests
|
||||||
|
import threading
|
||||||
|
|
||||||
|
app = flask.Flask(import_name=__name__)
|
||||||
|
|
||||||
|
@app.route(rule="/")
|
||||||
|
def index():
|
||||||
|
print("Can print inside the called function")
|
||||||
|
return "Okay, got it !"
|
||||||
|
|
||||||
|
def opener():
|
||||||
|
for _ in range(5):
|
||||||
|
requests.get("http://192.168.0.103/open")
|
||||||
|
|
||||||
|
@app.route(rule="/receiving", methods=["POST"])
|
||||||
|
def receiver():
|
||||||
|
#data = flask.request.get_json()
|
||||||
|
#for field in data: print(field, ":", data[field])
|
||||||
|
print(flask.request.get_data(as_text=True))
|
||||||
|
print(flask.request.args)
|
||||||
|
op = threading.Thread(target=opener)
|
||||||
|
op.start()
|
||||||
|
return flask.jsonify({"events":[{"event":"log","message":"server received sms successfully"}]})
|
||||||
|
|
||||||
|
if __name__=="__main__":
|
||||||
|
app.run(host="0.0.0.0", debug=True)
|
Loading…
Reference in a new issue