init
This commit is contained in:
parent
dc7a107ed5
commit
d386bb5a1c
|
@ -20,8 +20,8 @@
|
|||
|
||||
#include "camera_pins.h"
|
||||
|
||||
const char* ssid = "WeiFerL";
|
||||
const char* password = "IsMirBums!85";
|
||||
const char* ssid = "WIFI_SSID";
|
||||
const char* password = "PASS";
|
||||
|
||||
void startCameraServer();
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
#include "camera_pins.h"
|
||||
|
||||
#define ssid "WeiFerL"
|
||||
#define password "IsMirBums!85"
|
||||
#define ssid "WIFI_SSID"
|
||||
#define password "PASS"
|
||||
|
||||
void startCameraServer();
|
||||
|
||||
|
|
|
@ -36,8 +36,8 @@ const byte chips = 4; // Number of 8x8 modules linked together
|
|||
const int msglen = 500; // Maximum length of the message
|
||||
|
||||
// Set your wifi credetials here, for open wifi leave password empty
|
||||
const char* ssid = "WeiFerL";
|
||||
const char* password = "IsMirBums!85";
|
||||
const char* ssid = "WIFI_SSID";
|
||||
const char* password = "PASS";
|
||||
|
||||
// You can comment this section out for using DHCP
|
||||
//IPAddress ip(192, 168, 1, 85); // where xx is the desired IP Address
|
||||
|
|
|
@ -11,9 +11,9 @@
|
|||
#include <ArduinoOTA.h>
|
||||
|
||||
// ----- BEGIN WLAN-Netzwerk Einstellungen ----------------------------------
|
||||
const char* PRG_NAME_ID = "Led-Matrix";
|
||||
const char* ssid = "WeiFerL"; // SSID des vorhandenen WLANs
|
||||
const char* password = "IsMirBums!85"; // Passwort für das vorhandene WLAN
|
||||
const char* PRG_NAME_ID = "";
|
||||
const char* ssid = "WIFI_SSID"; // SSID des vorhandenen WLANs
|
||||
const char* password = "PASS"; // Passwort für das vorhandene WLAN
|
||||
// ----- END WLAN-Netzwerk Einstellungen ----------------------------------
|
||||
|
||||
void setup() {
|
||||
|
|
|
@ -26,8 +26,8 @@ IPAddress subnet(255, 255, 225, 0);
|
|||
int relayGPIOs[NUM_RELAYS] = {4};
|
||||
|
||||
// Replace with your network credentials
|
||||
const char* ssid = "WeiFerL";
|
||||
const char* password = "IsMirBums!85";
|
||||
const char* ssid = "WIFI_SSID";
|
||||
const char* password = "PASS";
|
||||
|
||||
const char* PARAM_INPUT_1 = "relay";
|
||||
const char* PARAM_INPUT_2 = "state";
|
||||
|
|
|
@ -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
|
|
@ -1,46 +0,0 @@
|
|||
|
||||
This directory is intended for project specific (private) libraries.
|
||||
PlatformIO will compile them to static libraries and link into executable file.
|
||||
|
||||
The source code of each library should be placed in a an own separate directory
|
||||
("lib/your_library_name/[here are source files]").
|
||||
|
||||
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
||||
|
||||
|--lib
|
||||
| |
|
||||
| |--Bar
|
||||
| | |--docs
|
||||
| | |--examples
|
||||
| | |--src
|
||||
| | |- Bar.c
|
||||
| | |- Bar.h
|
||||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||
| |
|
||||
| |--Foo
|
||||
| | |- Foo.c
|
||||
| | |- Foo.h
|
||||
| |
|
||||
| |- README --> THIS FILE
|
||||
|
|
||||
|- platformio.ini
|
||||
|--src
|
||||
|- main.c
|
||||
|
||||
and a contents of `src/main.c`:
|
||||
```
|
||||
#include <Foo.h>
|
||||
#include <Bar.h>
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
PlatformIO Library Dependency Finder will find automatically dependent
|
||||
libraries scanning project source files.
|
||||
|
||||
More information about PlatformIO Library Dependency Finder
|
||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
|
@ -1,15 +0,0 @@
|
|||
; PlatformIO Project Configuration File
|
||||
;
|
||||
; Build options: build flags, source filter
|
||||
; Upload options: custom upload port, speed and extra flags
|
||||
; Library options: dependencies, extra library storages
|
||||
; Advanced options: extra scripting
|
||||
;
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:d1_mini]
|
||||
platform = espressif8266
|
||||
board = d1_mini
|
||||
framework = arduino
|
||||
lib_deps = ottowinter/ESPAsyncWebServer-esphome@^1.3.0
|
|
@ -1,168 +0,0 @@
|
|||
/*********
|
||||
Rui Santos
|
||||
Complete project details at https://RandomNerdTutorials.com/esp8266-relay-module-ac-web-server/
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
*********/
|
||||
|
||||
// Import required libraries
|
||||
#include "ESP8266WiFi.h"
|
||||
#include "ESPAsyncWebServer.h"
|
||||
|
||||
// Set your Static IP address
|
||||
IPAddress local_IP(192, 168, 1, 111);
|
||||
// Set your Gateway IP address
|
||||
IPAddress gateway(192, 168, 0, 1);
|
||||
IPAddress subnet(255, 255, 225, 0);
|
||||
|
||||
// Set to true to define Relay as Normally Open (NO)
|
||||
#define RELAY_NO true
|
||||
|
||||
// Set number of relays
|
||||
#define NUM_RELAYS 5
|
||||
|
||||
// Assign each GPIO to a relay
|
||||
int relayGPIOs[NUM_RELAYS] = {5, 4, 14, 12, 13};
|
||||
|
||||
// Replace with your network credentials
|
||||
const char* ssid = "WeiFerL";
|
||||
const char* password = "IsMirBums!85";
|
||||
|
||||
const char* PARAM_INPUT_1 = "relay";
|
||||
const char* PARAM_INPUT_2 = "state";
|
||||
|
||||
// Create AsyncWebServer object on port 80
|
||||
AsyncWebServer server(80);
|
||||
|
||||
String relayState(int numRelay){
|
||||
if(RELAY_NO){
|
||||
if(digitalRead(relayGPIOs[numRelay-1])){
|
||||
return "";
|
||||
}
|
||||
else {
|
||||
return "checked";
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(digitalRead(relayGPIOs[numRelay-1])){
|
||||
return "checked";
|
||||
}
|
||||
else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
const char index_html[] PROGMEM = R"rawliteral(
|
||||
<!DOCTYPE HTML><html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<style>
|
||||
html {font-family: Arial; display: inline-block; text-align: center;}
|
||||
h2 {font-size: 3.0rem;}
|
||||
p {font-size: 3.0rem;}
|
||||
body {max-width: 600px; margin:0px auto; padding-bottom: 25px;}
|
||||
.switch {position: relative; display: inline-block; width: 120px; height: 68px}
|
||||
.switch input {display: none}
|
||||
.slider {position: absolute; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; border-radius: 34px}
|
||||
.slider:before {position: absolute; content: ""; height: 52px; width: 52px; left: 8px; bottom: 8px; background-color: #fff; -webkit-transition: .4s; transition: .4s; border-radius: 68px}
|
||||
input:checked+.slider {background-color: #2196F3}
|
||||
input:checked+.slider:before {-webkit-transform: translateX(52px); -ms-transform: translateX(52px); transform: translateX(52px)}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h2>ESP Web Server</h2>
|
||||
%BUTTONPLACEHOLDER%
|
||||
<script>function toggleCheckbox(element) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
if(element.checked){ xhr.open("GET", "/update?relay="+element.id+"&state=1", true); }
|
||||
else { xhr.open("GET", "/update?relay="+element.id+"&state=0", true); }
|
||||
xhr.send();
|
||||
}</script>
|
||||
</body>
|
||||
</html>
|
||||
)rawliteral";
|
||||
|
||||
// Replaces placeholder with button section in your web page
|
||||
String processor(const String& var){
|
||||
//Serial.println(var);
|
||||
if(var == "BUTTONPLACEHOLDER"){
|
||||
String buttons ="";
|
||||
for(int i=1; i<=NUM_RELAYS; i++){
|
||||
String relayStateValue = relayState(i);
|
||||
buttons+= "<h4>Relay #" + String(i) + " - GPIO " + relayGPIOs[i-1] + "</h4><label class=\"switch\"><input type=\"checkbox\" onchange=\"toggleCheckbox(this)\" id=\"" + String(i) + "\" "+ relayStateValue +"><span class=\"slider\"></span></label>";
|
||||
}
|
||||
return buttons;
|
||||
}
|
||||
return String();
|
||||
}
|
||||
|
||||
|
||||
void setup(){
|
||||
// Serial port for debugging purposes
|
||||
Serial.begin(115200);
|
||||
|
||||
// Set all relays to off when the program starts - if set to Normally Open (NO), the relay is off when you set the relay to HIGH
|
||||
for(int i=1; i<=NUM_RELAYS; i++){
|
||||
pinMode(relayGPIOs[i-1], OUTPUT);
|
||||
if(RELAY_NO){
|
||||
digitalWrite(relayGPIOs[i-1], HIGH);
|
||||
}
|
||||
else{
|
||||
digitalWrite(relayGPIOs[i-1], LOW);
|
||||
}
|
||||
}
|
||||
|
||||
// Connect to Wi-Fi
|
||||
WiFi.begin(ssid, password);
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(1000);
|
||||
Serial.println("Connecting to WiFi..");
|
||||
}
|
||||
|
||||
// Print ESP8266 Local IP Address
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
// Route for root / web page
|
||||
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||
request->send_P(200, "text/html", index_html, processor);
|
||||
});
|
||||
|
||||
// Send a GET request to <ESP_IP>/update?relay=<inputMessage>&state=<inputMessage2>
|
||||
server.on("/update", HTTP_GET, [] (AsyncWebServerRequest *request) {
|
||||
String inputMessage;
|
||||
String inputParam;
|
||||
String inputMessage2;
|
||||
String inputParam2;
|
||||
// GET input1 value on <ESP_IP>/update?relay=<inputMessage>
|
||||
if (request->hasParam(PARAM_INPUT_1) & request->hasParam(PARAM_INPUT_2)) {
|
||||
inputMessage = request->getParam(PARAM_INPUT_1)->value();
|
||||
inputParam = PARAM_INPUT_1;
|
||||
inputMessage2 = request->getParam(PARAM_INPUT_2)->value();
|
||||
inputParam2 = PARAM_INPUT_2;
|
||||
if(RELAY_NO){
|
||||
Serial.print("NO ");
|
||||
digitalWrite(relayGPIOs[inputMessage.toInt()-1], !inputMessage2.toInt());
|
||||
}
|
||||
else{
|
||||
Serial.print("NC ");
|
||||
digitalWrite(relayGPIOs[inputMessage.toInt()-1], inputMessage2.toInt());
|
||||
}
|
||||
}
|
||||
else {
|
||||
inputMessage = "No message sent";
|
||||
inputParam = "none";
|
||||
}
|
||||
Serial.println(inputMessage + inputMessage2);
|
||||
request->send(200, "text/plain", "OK");
|
||||
});
|
||||
// Start server
|
||||
server.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
|
@ -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
|
|
@ -22,8 +22,8 @@ See more at http://blog.squix.ch
|
|||
|
||||
// Setup
|
||||
|
||||
#define WIFI_SSID "WeiFerL"
|
||||
#define WIFI_PASS "IsMirBums!85"
|
||||
#define WIFI_SSID "WIFI_SSID"
|
||||
#define WIFI_PASS "PASS"
|
||||
#define WIFI_HOSTNAME "Wetter-Station"
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user