forked from anubisg1/hunter-wifi
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
major rework. added OTA support, added MQTT support, temporary remove…
…d Captive Portal
- Loading branch information
Showing
18 changed files
with
634 additions
and
474 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,39 @@ | ||
|
||
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 | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,15 @@ | ||
/** | ||
* Header file that includes default parameters for all parts of the program | ||
*/ | ||
|
||
#ifndef GLOBAL_CONFIG_H | ||
#define GLOBAL_CONFIG_H | ||
|
||
#define SERIAL_SPEED 9600 | ||
#define REM_PIN 16 | ||
#include <Arduino.h> | ||
|
||
// WIFi | ||
extern const String device_hostname; | ||
#define SSID_AP "WateringSystemAP" // SSID of the AP created to configure WiFi | ||
#define PWD_AP "" // Password of the AP created to configure WiFi | ||
|
||
//MQTT | ||
extern const char* mqtt_server; | ||
extern const int mqtt_port; //default is 1883 | ||
extern const char *mqtt_user; | ||
extern const char *mqtt_pass; | ||
|
||
#endif | ||
#ifndef GLOBAL_CONFIG_H | ||
#define GLOBAL_CONFIG_H | ||
|
||
#define SERIAL_SPEED 9600 | ||
#define REM_PIN 16 | ||
|
||
#define HOSTNAME "X-CORE" | ||
#define WIFI_SSID "your_wifi_ssid" | ||
#define WIFI_PASSWORD "your_wifi_password" | ||
#define MQTT_SERVER "server_ip_add" | ||
#define MQTT_PORT 1883 | ||
#define MQTT_USER "mqttuser" | ||
#define MQTT_PASSWORD "mqttpassword!" | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef MQTT_H | ||
#define MQTT_H | ||
|
||
#include <global_config.h> | ||
#include <PubSubClient.h> | ||
|
||
extern String TopicCheckIn; | ||
extern String TopicCommands; | ||
extern String TopicStatus; | ||
extern PubSubClient client; | ||
extern WiFiClient espClient; | ||
|
||
void mqtt_connect(); | ||
void mqttPublishResult(const char *toSend); | ||
void mqtt_subscribe_topics (); | ||
void callback(char* topic, byte* payload, unsigned int length); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifndef OTA_H | ||
#define OTA_H | ||
|
||
#include <ESPAsyncWebServer.h> | ||
|
||
void handleRoot(AsyncWebServerRequest *request); | ||
void handleUpdate(AsyncWebServerRequest *request); | ||
void handleDoUpdate(AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data, size_t len, bool final); | ||
void printProgress(size_t prg, size_t sz); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
#ifndef WEB_SERVER_H | ||
#define WEB_SERVER_H | ||
|
||
#include <ESPAsyncWebServer.h> | ||
extern AsyncWebServer server; | ||
|
||
void setupWebServer(); | ||
void setupAPIRoutes(); | ||
|
||
#ifndef WEB_SERVER_H | ||
#define WEB_SERVER_H | ||
|
||
#include <ESPAsyncWebServer.h> | ||
|
||
extern AsyncWebServer server; | ||
|
||
void setup_WebServer(); | ||
void setup_APIRoutes(); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
#ifndef WEB_SERVER_API_H | ||
#define WEB_SERVER_API_H | ||
|
||
#include <ESPAsyncWebServer.h> | ||
|
||
void startZoneRequest(AsyncWebServerRequest *request); | ||
void startProgramRequest(AsyncWebServerRequest *request); | ||
void stopZoneRequest(AsyncWebServerRequest *request); | ||
int getIdFromURL(AsyncWebServerRequest *request, String root); | ||
|
||
|
||
#ifndef WEB_SERVER_API_H | ||
#define WEB_SERVER_API_H | ||
|
||
#include <ESPAsyncWebServer.h> | ||
|
||
void startZoneRequest(AsyncWebServerRequest *request); | ||
void startProgramRequest(AsyncWebServerRequest *request); | ||
void stopZoneRequest(AsyncWebServerRequest *request); | ||
int getIdFromURL(AsyncWebServerRequest *request, String root); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
#ifndef WEB_SERVER_SCHEDULED_H | ||
#define WEB_SERVER_SHCEDULED_H | ||
|
||
void startZone(byte num, byte time, String webhook); | ||
void startProgram(byte num, String webhook); | ||
void stopZone(byte num, String webhook); | ||
|
||
#ifndef WEB_SERVER_SCHEDULED_H | ||
#define WEB_SERVER_SCHEDULED_H | ||
|
||
#include <ESPAsyncWebServer.h> | ||
|
||
void startZone(byte num, byte time, String webhook); | ||
void startProgram(byte num, String webhook); | ||
void stopZone(byte num, String webhook); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
#ifndef WIFI_H | ||
#define WIFI_H | ||
|
||
void setupWifi(); | ||
bool checkWifiConnection(bool firstTimeDisconnected); | ||
|
||
#endif | ||
|
||
#ifndef WIFI_H | ||
#define WIFI_H | ||
|
||
#include <ESP8266WiFi.h> | ||
|
||
void setup_wifi(); | ||
void reconnect(); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,19 @@ | ||
; 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_pro] | ||
platform = espressif8266 | ||
framework = arduino | ||
board = d1_mini_pro | ||
board_build.filesystem = littlefs | ||
lib_deps = | ||
ESPAsyncWiFiManager | ||
ArduinoJson | ||
ESP Async WebServer | ||
ESPAsyncTCP | ||
; 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_pro] | ||
platform = espressif8266 | ||
board = d1_mini_pro | ||
framework = arduino | ||
lib_deps = | ||
knolleary/PubSubClient@^2.8 | ||
me-no-dev/ESPAsyncTCP@^1.2.2 | ||
me-no-dev/ESP Async WebServer@^1.2.3 | ||
bblanchon/ArduinoJson@^6.18.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,4 @@ | ||
#include <global_config.h> | ||
|
||
const String device_hostname = "Hunter"; | ||
|
||
const char* mqtt_server = "MQTT_SERVER_IP"; | ||
const int mqtt_port = 1883; //default is 1883 | ||
const char *mqtt_user = "MQTT_USERNAME"; | ||
const char *mqtt_pass = "MQTT_PASSWORD"; | ||
#include <global_config.h> | ||
|
||
const String device_hostname = "X-CORE"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,28 @@ | ||
/** | ||
* First version: July 2020 - Eloi Codina Torras | ||
*/ | ||
#include <wifi.h> | ||
#include <FS.h> | ||
#include <ESP8266mDNS.h> | ||
|
||
#include <web_server.h> | ||
#include <global_config.h> | ||
|
||
AsyncWebServer server = AsyncWebServer(80); | ||
bool wifiDisconnected = false; | ||
|
||
void setup() { | ||
Serial.begin(SERIAL_SPEED); | ||
|
||
setupWifi(); | ||
setupWebServer(); | ||
|
||
/* if (!SPIFFS.begin()) { | ||
Serial.println("Error mounting the filesystem."); | ||
} else { | ||
Serial.println("Filesystem is now ready."); | ||
} | ||
*/ | ||
|
||
} | ||
|
||
void loop() { | ||
wifiDisconnected = checkWifiConnection(wifiDisconnected); | ||
MDNS.update(); | ||
} | ||
#include <ESP8266mDNS.h> | ||
|
||
#include <wifi.h> | ||
#include <mqtt.h> | ||
#include <web_server.h> | ||
|
||
AsyncWebServer server = AsyncWebServer(80); | ||
|
||
void setup() { | ||
Serial.begin(SERIAL_SPEED); | ||
WiFi.mode(WIFI_STA); | ||
setup_wifi(); | ||
setup_WebServer(); | ||
client.setServer(MQTT_SERVER, MQTT_PORT); | ||
client.setCallback(callback); | ||
Serial.print("IP address: "); | ||
Serial.println(WiFi.localIP()); | ||
Serial.printf("Ready! Open http://%s.local in your browser\n", HOSTNAME); | ||
} | ||
|
||
void loop() { | ||
if (!client.connected()) { | ||
reconnect(); | ||
} | ||
client.loop(); | ||
MDNS.update(); | ||
//timer.run(); | ||
} |
Oops, something went wrong.