diff --git a/reciver/.gitignore b/reciver/.gitignore new file mode 100644 index 0000000..89cc49c --- /dev/null +++ b/reciver/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/reciver/lora_reciver/.vscode/extensions.json b/reciver/.vscode/extensions.json similarity index 100% rename from reciver/lora_reciver/.vscode/extensions.json rename to reciver/.vscode/extensions.json diff --git a/reciver/lora_reciver/data/config.json b/reciver/data/config.json similarity index 100% rename from reciver/lora_reciver/data/config.json rename to reciver/data/config.json diff --git a/reciver/data/favicon.png b/reciver/data/favicon.png new file mode 100644 index 0000000..2547233 Binary files /dev/null and b/reciver/data/favicon.png differ diff --git a/reciver/data/index.html b/reciver/data/index.html new file mode 100644 index 0000000..c05ee2c --- /dev/null +++ b/reciver/data/index.html @@ -0,0 +1,27 @@ + + + + ESP WEB SERVER + + + + + + +
+

ESP WEB SERVER

+
+
+
+
+

GPIO 2

+

+ + +

+

State: %STATE%

+
+
+
+ + \ No newline at end of file diff --git a/reciver/data/style.css b/reciver/data/style.css new file mode 100644 index 0000000..4c50c8b --- /dev/null +++ b/reciver/data/style.css @@ -0,0 +1,109 @@ +html { + font-family: Arial, Helvetica, sans-serif; + display: inline-block; + text-align: center; +} + +h1 { + font-size: 1.8rem; + color: white; +} + +p { + font-size: 1.4rem; +} + +.topnav { + overflow: hidden; + background-color: #0A1128; +} + +body { + margin: 0; +} + +.content { + padding: 5%; +} + +.card-grid { + max-width: 800px; + margin: 0 auto; + display: grid; + grid-gap: 2rem; + grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); +} + +.card { + background-color: white; + box-shadow: 2px 2px 12px 1px rgba(140,140,140,.5); +} + +.card-title { + font-size: 1.2rem; + font-weight: bold; + color: #034078 +} + +input[type=submit] { + border: none; + color: #FEFCFB; + background-color: #034078; + padding: 15px 15px; + text-align: center; + text-decoration: none; + display: inline-block; + font-size: 16px; + width: 100px; + margin-right: 10px; + border-radius: 4px; + transition-duration: 0.4s; + } + +input[type=submit]:hover { + background-color: #1282A2; +} + +input[type=text], input[type=number], select { + width: 50%; + padding: 12px 20px; + margin: 18px; + display: inline-block; + border: 1px solid #ccc; + border-radius: 4px; + box-sizing: border-box; +} + +label { + font-size: 1.2rem; +} +.value{ + font-size: 1.2rem; + color: #1282A2; +} +.state { + font-size: 1.2rem; + color: #1282A2; +} +button { + border: none; + color: #FEFCFB; + padding: 15px 32px; + text-align: center; + font-size: 16px; + width: 100px; + border-radius: 4px; + transition-duration: 0.4s; +} +.button-on { + background-color: #034078; +} +.button-on:hover { + background-color: #1282A2; +} +.button-off { + background-color: #858585; +} +.button-off:hover { + background-color: #252524; +} \ No newline at end of file diff --git a/reciver/lora_reciver/data/wifimanager.html b/reciver/data/wifimanager.html similarity index 100% rename from reciver/lora_reciver/data/wifimanager.html rename to reciver/data/wifimanager.html diff --git a/reciver/lora_reciver/include/README b/reciver/include/README similarity index 100% rename from reciver/lora_reciver/include/README rename to reciver/include/README diff --git a/reciver/lora_reciver/lib/README b/reciver/lib/README similarity index 100% rename from reciver/lora_reciver/lib/README rename to reciver/lib/README diff --git a/reciver/lora_reciver/platformio.ini b/reciver/platformio.ini similarity index 100% rename from reciver/lora_reciver/platformio.ini rename to reciver/platformio.ini diff --git a/reciver/lora_reciver/src/config.cpp b/reciver/src/config.cpp similarity index 100% rename from reciver/lora_reciver/src/config.cpp rename to reciver/src/config.cpp diff --git a/reciver/lora_reciver/src/config.hpp b/reciver/src/config.hpp similarity index 100% rename from reciver/lora_reciver/src/config.hpp rename to reciver/src/config.hpp diff --git a/reciver/lora_reciver/src/display.cpp b/reciver/src/display.cpp similarity index 100% rename from reciver/lora_reciver/src/display.cpp rename to reciver/src/display.cpp diff --git a/reciver/lora_reciver/src/display.hpp b/reciver/src/display.hpp similarity index 100% rename from reciver/lora_reciver/src/display.hpp rename to reciver/src/display.hpp diff --git a/reciver/lora_reciver/src/lorahandler.cpp b/reciver/src/lorahandler.cpp similarity index 100% rename from reciver/lora_reciver/src/lorahandler.cpp rename to reciver/src/lorahandler.cpp diff --git a/reciver/lora_reciver/src/lorahandler.hpp b/reciver/src/lorahandler.hpp similarity index 100% rename from reciver/lora_reciver/src/lorahandler.hpp rename to reciver/src/lorahandler.hpp diff --git a/reciver/lora_reciver/src/main.cpp b/reciver/src/main.cpp similarity index 100% rename from reciver/lora_reciver/src/main.cpp rename to reciver/src/main.cpp diff --git a/reciver/lora_reciver/src/mqtt.cpp b/reciver/src/mqtt.cpp similarity index 100% rename from reciver/lora_reciver/src/mqtt.cpp rename to reciver/src/mqtt.cpp diff --git a/reciver/lora_reciver/src/mqtt.hpp b/reciver/src/mqtt.hpp similarity index 100% rename from reciver/lora_reciver/src/mqtt.hpp rename to reciver/src/mqtt.hpp diff --git a/reciver/lora_reciver/src/wifi.cpp b/reciver/src/wifi.cpp similarity index 100% rename from reciver/lora_reciver/src/wifi.cpp rename to reciver/src/wifi.cpp diff --git a/reciver/lora_reciver/src/wifi.hpp b/reciver/src/wifi.hpp similarity index 100% rename from reciver/lora_reciver/src/wifi.hpp rename to reciver/src/wifi.hpp diff --git a/reciver/lora_reciver/test/README b/reciver/test/README similarity index 100% rename from reciver/lora_reciver/test/README rename to reciver/test/README diff --git a/sender/doc/board_pins.webp b/sender/doc/board_pins.webp deleted file mode 100644 index 8f503df..0000000 Binary files a/sender/doc/board_pins.webp and /dev/null differ diff --git a/sender/platformio.ini b/sender/platformio.ini index 0f50a70..0b5c2d2 100644 --- a/sender/platformio.ini +++ b/sender/platformio.ini @@ -21,3 +21,4 @@ lib_deps = peterus/esp-logger@^1.0.0 sandeepmistry/LoRa@^0.8.0 olikraus/U8g2_for_Adafruit_GFX@^1.8.0 + milesburton/DallasTemperature@^3.11.0 diff --git a/sender/src/eink.cpp b/sender/src/eink.cpp index 71e4301..285e1ab 100644 --- a/sender/src/eink.cpp +++ b/sender/src/eink.cpp @@ -10,135 +10,132 @@ Eink::Eink(int csPin, int dcPin, int rstPin, int busyPin) { } -void Eink::setup_eink() { - - SPI.begin(EPD_SCLK, EPD_MISO, EPD_MOSI); - eink.init(115200, true, 2, false); - eink.setRotation(1); - eink.fillScreen(GxEPD_WHITE); - eink.setTextColor(GxEPD_BLACK); - eink.setFullWindow(); - u8g2Fonts.begin(eink); - u8g2Fonts.setFont(u8g2_font_7x13_tf); - u8g2Fonts.setForegroundColor(GxEPD_BLACK); // apply Adafruit GFX color - u8g2Fonts.setBackgroundColor(GxEPD_WHITE); +void Eink::setup_eink() +{ - - logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "EINK", "Display init done!"); + SPI.begin(EPD_SCLK, EPD_MISO, EPD_MOSI); + eink.init(115200, true, 2, false); + eink.setRotation(1); + eink.fillScreen(GxEPD_WHITE); + eink.setTextColor(GxEPD_BLACK); + eink.setFullWindow(); + u8g2Fonts.begin(eink); + u8g2Fonts.setFont(u8g2_font_7x13_tf); + u8g2Fonts.setForegroundColor(GxEPD_BLACK); // apply Adafruit GFX color + u8g2Fonts.setBackgroundColor(GxEPD_WHITE); + + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "EINK", "Display init done!"); } -void Eink::show_display(String header, int wait){ - logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "EINK", "One line: %s", header.c_str()); - eink.setFont(&FreeMonoBold9pt7b); - eink.setCursor(0,10); - eink.println(header); - eink.println("Line 2"); - eink.println("Line 3"); - eink.println("Line 4"); - eink.display(); - delay(wait); +void Eink::show_display(String header, int wait) +{ + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "EINK", "One line: %s", header.c_str()); + eink.setFont(&FreeMonoBold9pt7b); + eink.setCursor(0, 10); + eink.println(header); + eink.println("Line 2"); + eink.println("Line 3"); + eink.println("Line 4"); + eink.display(); + delay(wait); - int16_t x1, y1; - uint16_t w, h; - eink.getTextBounds(header, 0, 0, &x1, &y1, &w, &h); + int16_t x1, y1; + uint16_t w, h; + eink.getTextBounds(header, 0, 0, &x1, &y1, &w, &h); } - -void Eink::show_temp(float temperature){ +void Eink::show_temp(float temperature) +{ logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "EINK", "Show temp: %f", temperature); - - int textX = 40; - u8g2Fonts.setFont(u8g2_font_fur42_tf ); + + int textX = 40; + //u8g2Fonts.setFont(u8g2_font_fur42_tf); + u8g2Fonts.setFont(u8g2_font_inr46_mf); drawString(textX, 70, String(temperature, 1) + "°", LEFT); drawMercury(temperature); } -void Eink::drawSignalBars(int x, int y, int percentage) { +void Eink::drawSignalBars(int x, int y, int percentage) +{ // Define stapler properties const int staplerWidth = 4; const int staplerHeight = 14; const int staplerSpacing = 2; - int numBars = percentage / 20; + int numBars = percentage / 20; // Limit numBars to the maximum (5 staplers) - numBars = min(numBars, 5); // Ensure no more than 5 staplers are drawn + numBars = min(numBars, 5); // Ensure no more than 5 staplers are drawn int staplerX; int currentHeight; int staplerY; // Loop to draw staplers with variable heights and bottom alignment - for (int i = 0; i < numBars; i++) { + for (int i = 0; i < numBars; i++) + { // Calculate x-position for each stapler staplerX = x + i * (staplerWidth + staplerSpacing); // Calculate stapler height based on the number of bars (1 to 5) - currentHeight = staplerHeight * (i + 1) / 6; // Scales from 1/5 to full height + currentHeight = staplerHeight * (i + 1) / 6; // Scales from 1/5 to full height // Calculate y-position for bottom alignment - staplerY = y - currentHeight; // Subtract height for bottom placement + staplerY = y - currentHeight; // Subtract height for bottom placement // Draw the stapler body (rectangle) eink.fillRect(staplerX, staplerY, staplerWidth, currentHeight, GxEPD_BLACK); } - - drawString(staplerX +staplerWidth +2, staplerY , String(percentage) + "%", LEFT); + + drawString(staplerX + staplerWidth + 2, staplerY, String(percentage) + "%", LEFT); } void Eink::display(bool partialupgrade) { logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "EINK", "Update display"); - + eink.display(partialupgrade); } -void Eink::drawMercury(float temperature){ +void Eink::drawMercury(float temperature) +{ int x = 20; int y = 30; int height = 60; int width = 10; int mercuryLevel = map(temperature, 0.0, 100.0, 20, height); int radius = 14; - eink.drawRect(x, y - radius + 2, width, height,GxEPD_BLACK ); + eink.drawRect(x, y - radius + 2, width, height, GxEPD_BLACK); - eink.drawCircle(x + (width/2) , y + height, radius, GxEPD_BLACK); - eink.fillCircle(x + (width/2), y + height, radius - 2, GxEPD_BLACK); + eink.drawCircle(x + (width / 2), y + height, radius, GxEPD_BLACK); + eink.fillCircle(x + (width / 2), y + height, radius - 2, GxEPD_BLACK); eink.fillRect( - x + 2, - y + height - mercuryLevel - radius + 2, - width - 4, - mercuryLevel, - GxEPD_BLACK - ); - + x + 2, + y + height - mercuryLevel - radius + 2, + width - 4, + mercuryLevel, + GxEPD_BLACK); } -void Eink::drawBattery(int x, int y) { - - uint8_t percentage = 100; - float voltage = analogRead(35) / 4096.0 * 7.46; - if (voltage > 1 ) { // Only display if there is a valid reading - logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "EINK", "Voltage: %d", voltage); - percentage = 2836.9625 * pow(voltage, 4) - 43987.4889 * pow(voltage, 3) + 255233.8134 * pow(voltage, 2) - 656689.7123 * voltage + 632041.7303; - if (voltage >= 4.20) percentage = 100; - if (voltage <= 3.50) percentage = 0; - eink.drawRect(x + 15, y - 12, 19, 10, GxEPD_BLACK); - eink.fillRect(x + 34, y - 10, 2, 5, GxEPD_BLACK); - eink.fillRect(x + 17, y - 10, 15 * percentage / 100.0, 6, GxEPD_BLACK); - drawString(x + 60, y - 11, String(percentage) + "%", RIGHT); - } +void Eink::drawBattery(int x, int y, int percentage) +{ + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "EINK", "drawBattery: %d %", percentage); + eink.drawRect(x + 15, y - 12, 19, 10, GxEPD_BLACK); + eink.fillRect(x + 34, y - 10, 2, 5, GxEPD_BLACK); + eink.fillRect(x + 17, y - 10, 15 * percentage / 100.0, 6, GxEPD_BLACK); + drawString(x + 60, y - 11, String(percentage) + "%", RIGHT); } -void Eink::drawString(int x, int y, String text, alignmentType alignment) { - logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "EINK drawstring", "x: %d", y); - logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "EINK drawstring", "y: %d", x); - - - int16_t x1, y1; //the bounds of x,y and w and h of the variable 'text' in pixels. +void Eink::drawString(int x, int y, String text, alignmentType alignment) +{ + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "EINK drawstring", "x: %d", y); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "EINK drawstring", "y: %d", x); + + int16_t x1, y1; // the bounds of x,y and w and h of the variable 'text' in pixels. uint16_t w, h; eink.setTextWrap(false); eink.getTextBounds(text, x, y, &x1, &y1, &w, &h); - if (alignment == RIGHT) x = x - w; - if (alignment == CENTER) x = x - w / 2; - u8g2Fonts.setCursor(x+2, y + h); + if (alignment == RIGHT) + x = x - w; + if (alignment == CENTER) + x = x - w / 2; + u8g2Fonts.setCursor(x + 2, y + h); u8g2Fonts.print(text); - } \ No newline at end of file diff --git a/sender/src/eink.hpp b/sender/src/eink.hpp index d391fab..13b29a8 100644 --- a/sender/src/eink.hpp +++ b/sender/src/eink.hpp @@ -4,18 +4,7 @@ #include #include "epd/GxEPD2_213.h" #include - - - - -#define EPD_MOSI (23) -#define EPD_MISO (-1) //elink no use -#define EPD_SCLK (18) - -#define EPD_BUSY (4) -#define EPD_RSET (16) -#define EPD_DC (17) -#define EPD_CS (5) +#include "pins.hpp" class Eink { public: @@ -24,7 +13,7 @@ public: void setup_eink(); void show_temp(float temperature); void show_display(String header, int wait=100); - void drawBattery(int x, int y); + void drawBattery(int x, int y, int percentage=100); void drawSignalBars(int x, int y, int numBars); void display(bool partialupgrade = false); diff --git a/sender/src/io.cpp b/sender/src/io.cpp new file mode 100644 index 0000000..91cf32b --- /dev/null +++ b/sender/src/io.cpp @@ -0,0 +1,65 @@ + +#include "io.hpp" +#include "logger.h" +#include "pins.hpp" +#include "WiFi.h" +#include "driver/adc.h" +#include +#include + + +extern logging::Logger logger; + +IO::IO() { +} + +void IO::setup_io() { + oneWire.begin(DI_DALLAS); + sensors.begin(); + sensors.setResolution(10); +} + +void IO::set_low_power() { + digitalWrite ( DI_LED, LOW ); + setCpuFrequencyMhz(80); + WiFi.mode(WIFI_OFF); + btStop(); + + esp_wifi_stop(); + esp_bt_controller_disable(); + + +} + +uint8_t IO::read_battery() { + uint8_t percentage = 100; + + float voltage = analogRead(ADC_BATTERY) / 4096.0 * 7.46; + //float voltage = analogRead(35) / 4096.0 * 7.46; + if (voltage > 1 ) { // Only display if there is a valid reading + percentage = 2836.9625 * pow(voltage, 4) - 43987.4889 * pow(voltage, 3) + 255233.8134 * pow(voltage, 2) - 656689.7123 * voltage + 632041.7303; + if (voltage >= 4.20) percentage = 100; + if (voltage <= 3.50) percentage = 0; + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "io", "Voltage: %f", voltage); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "io", "Percentage: %d", percentage); + } + + return percentage; + +} + +float IO::read_temp() { + + sensors.requestTemperatures(); // Request temperature readings + float tempC = sensors.getTempCByIndex(0); + if (tempC != DEVICE_DISCONNECTED_C) + { + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "io", "Temp: %f", tempC); + }else{ + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "io", "Couldn't read temp"); + } + float chipTemp = temperatureRead(); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "io", "chipTemp: %f", chipTemp); + return tempC; + +} \ No newline at end of file diff --git a/sender/src/io.hpp b/sender/src/io.hpp new file mode 100644 index 0000000..d60da20 --- /dev/null +++ b/sender/src/io.hpp @@ -0,0 +1,22 @@ +#ifndef IO_H +#define IO_H + +#include +#include +#include + + +class IO { +public: + IO(); + void setup_io(); + void set_low_power(); + float read_temp(); + uint8_t read_battery(); +private: + OneWire oneWire; + DallasTemperature sensors; + +}; + +#endif /* IO_H */ \ No newline at end of file diff --git a/sender/src/lorahandler.cpp b/sender/src/lorahandler.cpp index 476b5b9..6c8deeb 100644 --- a/sender/src/lorahandler.cpp +++ b/sender/src/lorahandler.cpp @@ -1,6 +1,7 @@ #include "config.hpp" #include "lorahandler.hpp" #include "logger.h" +#include "pins.hpp" extern logging::Logger logger; extern Config config; @@ -9,8 +10,8 @@ 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); + SPI.begin(RADIO_SCK, RADIO_MISO, RADIO_MOSI, RADIO_CS); + LoRa.setPins(RADIO_CS, RADIO_RST, RADIO_IRQ); long freq = config.loraConfig.frequency; if (!LoRa.begin(freq)) diff --git a/sender/src/lorahandler.hpp b/sender/src/lorahandler.hpp index 8b5a1a3..2aac8f4 100644 --- a/sender/src/lorahandler.hpp +++ b/sender/src/lorahandler.hpp @@ -5,13 +5,6 @@ #include #include -#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 - struct ReceivedLoRaPacket { String text; int rssi; diff --git a/sender/src/main.cpp b/sender/src/main.cpp index 53a2b20..b4f4286 100644 --- a/sender/src/main.cpp +++ b/sender/src/main.cpp @@ -1,30 +1,41 @@ #include #include "config.hpp" #include "eink.hpp" +#include "io.hpp" logging::Logger logger; -Eink eink; +Eink eink; +IO io; void setup() { - Serial.begin(115200); - - #ifndef DEBUG - logger.setDebugLevel(logging::LoggerLevel::LOGGER_LEVEL_INFO); - #endif - delay(100); - + Serial.begin(115200); +// TODO check if pin 22(ledbuiltin 2) is a led +#ifndef DEBUG + logger.setDebugLevel(logging::LoggerLevel::LOGGER_LEVEL_INFO); +#endif + //delay(100); + io.set_low_power(); + io.setup_io(); + uint8_t battery = io.read_battery(); + float temp = io.read_temp(); eink.setup_eink(); - delay(100); + // delay(100); + + eink.drawBattery(186, 14, battery); // eink width 250 - drawbattery width + eink.drawSignalBars(180 - 24 - 4, 12, 84); // drawbattery width - drawsignal + eink.show_temp(30.0); + eink.display(); - eink.drawBattery(186, 14); // eink width 250 - drawbattery width - eink.drawSignalBars(180 - 24 - 4, 12, 84); // drawbattery width - drawsignal - eink.show_temp(30.0); - eink.display(); } void loop() { -} + + + eink.show_temp(30.0); + eink.display(true); + sleep(10); +} diff --git a/sender/src/pins.hpp b/sender/src/pins.hpp new file mode 100644 index 0000000..e6670d1 --- /dev/null +++ b/sender/src/pins.hpp @@ -0,0 +1,28 @@ +#ifndef PINS_H +#define PINS_H + +// Pin assignments for EPD display +const int EPD_MOSI = 23; +const int EPD_MISO = -1; // elink no use +const int EPD_SCLK = 18; + +const int EPD_BUSY = 4; +const int EPD_RSET = 16; +const int EPD_DC = 17; +const int EPD_CS = 5; + +// Pin assignments for LORA module +const int RADIO_SCK = 5; +const int RADIO_MISO = 19; +const int RADIO_MOSI = 27; +const int RADIO_CS = 18; // CS --> NSS +const int RADIO_RST = 14; +const int RADIO_IRQ = 26; // IRQ --> DIO0 + +// Battery pin +const int ADC_BATTERY = 12; //builtin = 35 + +const int DI_DALLAS = 32; +// Builtin LED +const int DI_LED = 22; +#endif /* PINS_H */ \ No newline at end of file