Added display and lora
This commit is contained in:
parent
7f477f5cc8
commit
2b9036abcb
|
|
@ -0,0 +1,33 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>ESP Wi-Fi Manager</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="icon" href="data:,">
|
||||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="topnav">
|
||||
<h1>ESP Wi-Fi Manager</h1>
|
||||
</div>
|
||||
<div class="content">
|
||||
<div class="card-grid">
|
||||
<div class="card">
|
||||
<form action="/" method="POST">
|
||||
<p>
|
||||
<label for="ssid">SSID</label>
|
||||
<input type="text" id ="ssid" name="ssid"><br>
|
||||
<label for="pass">Password</label>
|
||||
<input type="text" id ="pass" name="pass"><br>
|
||||
<label for="ip">IP Address</label>
|
||||
<input type="text" id ="ip" name="ip" value="192.168.1.200"><br>
|
||||
<label for="gateway">Gateway Address</label>
|
||||
<input type="text" id ="gateway" name="gateway" value="192.168.1.1"><br>
|
||||
<input type ="submit" value ="Submit">
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -20,3 +20,5 @@ lib_deps =
|
|||
bblanchon/ArduinoJson@^7.0.4
|
||||
peterus/esp-logger@^1.0.0
|
||||
knolleary/PubSubClient@^2.8
|
||||
sandeepmistry/LoRa@^0.8.0
|
||||
thingpulse/ESP8266 and ESP32 OLED driver for SSD1306 displays@^4.5.0
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <Arduino.h>
|
||||
#include <FS.h>
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
class MqttConfig {
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,77 @@
|
|||
#include "display.hpp"
|
||||
#include "config.hpp"
|
||||
#include "logger.h"
|
||||
|
||||
extern logging::Logger logger;
|
||||
|
||||
// Constructor to initialize the display with I2C parameters
|
||||
Display::Display()
|
||||
: display(DISPLAY_ADDRESS, DISPLAY_SDA, DISPLAY_SCL) {
|
||||
}
|
||||
|
||||
void Display::setup_display() {
|
||||
if (!display.init()) {
|
||||
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "DISPLAY", "Display initialization failed!");
|
||||
return;
|
||||
}
|
||||
display.flipScreenVertically();
|
||||
display.setFont(ArialMT_Plain_10);
|
||||
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display.drawString(5,5,"LoRa Receiver");
|
||||
display.display();
|
||||
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "DISPLAY", "Display init done!");
|
||||
}
|
||||
|
||||
void Display::display_toggle(bool toggle) {
|
||||
displayOn = toggle;
|
||||
if (displayOn) {
|
||||
display.displayOn();
|
||||
} else {
|
||||
display.displayOff();
|
||||
}
|
||||
}
|
||||
|
||||
void Display::cleanTFT() {
|
||||
display.clear();
|
||||
display.display();
|
||||
}
|
||||
void Display::show_display(String header, int wait) {
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "DISPLAY", "One line: %s", header.c_str());
|
||||
//cleanTFT();
|
||||
//display.drawString(0, 0, header);
|
||||
display.drawString(5,5,"LoRa Receiver");
|
||||
display.display();
|
||||
delay(wait);
|
||||
}
|
||||
|
||||
void Display::show_display(String header, String line1, int wait) {
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "DISPLAY", "Two lines: %s, %s", header.c_str(), line1.c_str());
|
||||
cleanTFT();
|
||||
display.drawString(0, 0, header);
|
||||
display.drawString(0, 12, line1);
|
||||
display.display();
|
||||
delay(wait);
|
||||
}
|
||||
|
||||
void Display::show_display(String header, String line1, String line2, int wait) {
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "DISPLAY", "Three lines: %s, %s, %s", header.c_str(), line1.c_str(), line2.c_str());
|
||||
cleanTFT();
|
||||
display.drawString(0, 0, header);
|
||||
display.drawString(0, 12, line1);
|
||||
display.drawString(0, 24, line2);
|
||||
display.display();
|
||||
delay(wait);
|
||||
}
|
||||
|
||||
void Display::show_display(String header, String line1, String line2, String line3, int wait) {
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "DISPLAY", "Four lines: %s, %s, %s, %s", header.c_str(), line1.c_str(), line2.c_str(), line3.c_str());
|
||||
cleanTFT();
|
||||
display.drawString(0, 0, header);
|
||||
display.drawString(0, 12, line1);
|
||||
display.drawString(0, 24, line2);
|
||||
display.drawString(0, 36, line3);
|
||||
display.display();
|
||||
delay(wait);
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
#ifndef DISPLAY_H
|
||||
#define DISPLAY_H
|
||||
|
||||
#include <Arduino.h>
|
||||
//#include <SSD1306.h>
|
||||
#include "SSD1306Wire.h"
|
||||
#define DISPLAY_ADDRESS 0x3c // CS --> NSS
|
||||
#define DISPLAY_SDA 4
|
||||
#define DISPLAY_SCL 15 // IRQ --> DIO0
|
||||
|
||||
|
||||
class Display {
|
||||
public:
|
||||
Display();
|
||||
|
||||
void setup_display();
|
||||
void display_toggle(bool toggle);
|
||||
void cleanTFT();
|
||||
|
||||
void show_display(String header, int wait = 0);
|
||||
void show_display(String header, String line1, int wait = 0);
|
||||
void show_display(String header, String line1, String line2, int wait = 0);
|
||||
void show_display(String header, String line1, String line2, String line3, int wait = 0);
|
||||
|
||||
private:
|
||||
SSD1306Wire display;
|
||||
bool displayOn;
|
||||
};
|
||||
|
||||
#endif /* DISPLAY_H */
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
#include "config.hpp"
|
||||
#include "lorahandler.hpp"
|
||||
#include "logger.h"
|
||||
|
||||
extern logging::Logger logger;
|
||||
extern Config config;
|
||||
|
||||
|
||||
void LoraHandler::setup()
|
||||
{
|
||||
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "LoRa", "Set SPI pins!");
|
||||
SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS);
|
||||
LoRa.setPins(LORA_CS, LORA_RST, LORA_IRQ);
|
||||
|
||||
long freq = config.loraConfig.frequency;
|
||||
if (!LoRa.begin(freq)) {
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "LoRa", "Starting LoRa failed!");
|
||||
//show_display("ERROR", "Starting LoRa failed!");
|
||||
while (true) {
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
LoRa.setSpreadingFactor(config.loraConfig.spreadingFactor);
|
||||
LoRa.setSignalBandwidth(config.loraConfig.signalBandwidth);
|
||||
LoRa.setCodingRate4(config.loraConfig.codingRate4);
|
||||
LoRa.enableCrc();
|
||||
LoRa.setTxPower(config.loraConfig.power);
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "LoRa", "LoRa init done!");
|
||||
String currentLoRainfo = "LoRa Freq: " + String(config.loraConfig.frequency) + " / SF:" + String(config.loraConfig.spreadingFactor) + " / CR: " + String(config.loraConfig.codingRate4);
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "LoRa", currentLoRainfo.c_str());
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
#ifndef LORAHANDLER_H
|
||||
#define LORAHANDLER_H
|
||||
|
||||
#include "config.hpp"
|
||||
#include <SPI.h>
|
||||
#include <LoRa.h>
|
||||
|
||||
#define LORA_SCK 5
|
||||
#define LORA_MISO 19
|
||||
#define LORA_MOSI 27
|
||||
#define LORA_CS 18 // CS --> NSS
|
||||
#define LORA_RST 14
|
||||
#define LORA_IRQ 26 // IRQ --> DIO0
|
||||
|
||||
|
||||
class LoraHandler {
|
||||
public:
|
||||
void setup();
|
||||
private:
|
||||
};
|
||||
|
||||
#endif /* LORAHANDLER_H */
|
||||
|
|
@ -3,19 +3,24 @@
|
|||
#include "wifi.hpp"
|
||||
#include "mqtt.hpp"
|
||||
#include "config.hpp"
|
||||
|
||||
#include "lorahandler.hpp"
|
||||
#include "display.hpp"
|
||||
#include <WiFi.h>
|
||||
|
||||
Config config;
|
||||
WiFiServer server(80);
|
||||
WiFiClient wclient;
|
||||
Mqtt mqtt(wclient);
|
||||
LoraHandler lora;
|
||||
Display display;
|
||||
|
||||
|
||||
#define TRIGGER_PIN 0
|
||||
void checkButton();
|
||||
|
||||
bool portalRunning = false;
|
||||
logging::Logger logger;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
|
@ -34,14 +39,23 @@ void setup()
|
|||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "MAIN", "COnfig not loaded yet...");
|
||||
}
|
||||
delay(100);
|
||||
display.setup_display();
|
||||
// display.show_display("hej");
|
||||
setupWifi("island_temp", false);
|
||||
|
||||
mqtt.mqttSetup();
|
||||
// server.begin();
|
||||
//mqtt.mqttSetup();
|
||||
//lora.setup();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
/*
|
||||
display.show_display("First", 10);
|
||||
sleep(10);
|
||||
display.show_display("First line", "second line", 10);
|
||||
sleep(10);
|
||||
display.show_display("First line", "second line", "Third line ", 10);
|
||||
sleep(10);
|
||||
|
||||
mqtt.mqttRun();
|
||||
if (portalRunning)
|
||||
|
|
@ -50,6 +64,7 @@ void loop()
|
|||
}
|
||||
mqtt.mqttPublish("test/sensor", "123");
|
||||
checkButton();
|
||||
sleep(10);*/
|
||||
}
|
||||
|
||||
void checkButton()
|
||||
|
|
|
|||
Loading…
Reference in New Issue