Added Dallas + moved reciver

This commit is contained in:
Simon 2024-07-12 22:35:40 +02:00
parent 7cd53b63f8
commit bab9d3e5d2
32 changed files with 360 additions and 112 deletions

5
reciver/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

BIN
reciver/data/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 717 B

27
reciver/data/index.html Normal file
View File

@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<title>ESP WEB SERVER</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="icon" type="image/png" href="favicon.png">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
</head>
<body>
<div class="topnav">
<h1>ESP WEB SERVER</h1>
</div>
<div class="content">
<div class="card-grid">
<div class="card">
<p class="card-title"><i class="fas fa-lightbulb"></i> GPIO 2</p>
<p>
<a href="on"><button class="button-on">ON</button></a>
<a href="off"><button class="button-off">OFF</button></a>
</p>
<p class="state">State: %STATE%</p>
</div>
</div>
</div>
</body>
</html>

109
reciver/data/style.css Normal file
View File

@ -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;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

View File

@ -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

View File

@ -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);
}

View File

@ -4,18 +4,7 @@
#include <GxEPD2_BW.h>
#include "epd/GxEPD2_213.h"
#include <U8g2_for_Adafruit_GFX.h>
#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);

65
sender/src/io.cpp Normal file
View File

@ -0,0 +1,65 @@
#include "io.hpp"
#include "logger.h"
#include "pins.hpp"
#include "WiFi.h"
#include "driver/adc.h"
#include <esp_wifi.h>
#include <esp_bt.h>
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;
}

22
sender/src/io.hpp Normal file
View File

@ -0,0 +1,22 @@
#ifndef IO_H
#define IO_H
#include <Arduino.h>
#include <OneWire.h>
#include <DallasTemperature.h>
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 */

View File

@ -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))

View File

@ -5,13 +5,6 @@
#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
struct ReceivedLoRaPacket {
String text;
int rssi;

View File

@ -1,30 +1,41 @@
#include <logger.h>
#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);
}

28
sender/src/pins.hpp Normal file
View File

@ -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 */