Commit a77645b5 authored by Eric Duminil's avatar Eric Duminil
Browse files

Trying to avoid conflict with ESP8266

parent 3cf93f02
#include "lorawan.h"
#if defined(ESP32)
namespace config {
// Values should be defined in config.h
......@@ -21,7 +22,6 @@ const lmic_pinmap lmic_pins = { .nss = 18, .rxtx = LMIC_UNUSED_PIN, .rst = 14, .
// More info : https://www.thethingsnetwork.org/docs/applications/mqtt/quick-start.html
//TODO: Add infos to webserver (last timestamp, sending interval, connected or not?)
//TODO: Merge back to other branch (and other git)
//TODO: compile for both boards, and check ESP32 && LORA
void os_getArtEui(u1_t *buf) {
......@@ -141,15 +141,17 @@ namespace lorawan {
} else {
uint8_t buff[3];
// Mapping CO2 from 0ppm to 5100ppm to [0, 255], with 20ppm increments.
buff[0] = (min(max(sensor::co2, 0), 5100) + 10) / 20;
buff[0] = (util::min(util::max(sensor::co2, 0), 5100) + 10) / 20;
// Mapping temperatures from [-10°C, 41°C] to [0, 255], with 0.2°C increment
buff[1] = static_cast<uint8_t>((min(max(sensor::temperature, -10), 41) + 10.1f) * 5);
buff[1] = static_cast<uint8_t>((util::min(util::max(sensor::temperature, -10), 41) + 10.1f) * 5);
// Mapping humidity from [0%, 100%] to [0, 200], with 0.5°C increment (0.4°C would also be possible)
buff[2] = static_cast<uint8_t>(min(max(sensor::humidity, 0) + 0.25f, 100) * 2);
buff[2] = static_cast<uint8_t>(util::min(util::max(sensor::humidity, 0) + 0.25f, 100) * 2);
Serial.print(F("LoRa - Payload : '0x"));
Serial.print(F("LoRa - Payload : '"));
printHex2(buff[0]);
Serial.print(" ");
printHex2(buff[1]);
Serial.print(" ");
printHex2(buff[2]);
Serial.print(F("', "));
Serial.print(buff[0] * 20);
......@@ -202,3 +204,4 @@ namespace lorawan {
void onEvent(ev_t ev) {
lorawan::onEvent(ev);
}
#endif
#ifndef AMPEL_LORAWAN_H_
#define AMPEL_LORAWAN_H_
#if defined(ESP32)
#include <Arduino.h>
#include <lmic.h>
#include <hal/hal.h>
......@@ -22,3 +22,4 @@ namespace lorawan {
}
#endif
#endif
......@@ -24,8 +24,18 @@ namespace ntp {
String getLocalTime();
}
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
namespace util {
template<typename Tpa, typename Tpb>
inline auto min(const Tpa &a, const Tpb &b) -> decltype(a < b ? a : b) {
return b < a ? b : a;
}
template<typename Tpa, typename Tpb>
inline auto max(const Tpa &a, const Tpb &b) -> decltype(b > a ? b : a) {
return b > a ? b : a;
}
}
#define seconds() (millis() / 1000UL)
extern uint32_t max_loop_duration;
const extern String SENSOR_ID;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment