mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-10 07:26:38 +02:00
Merge pull request #76 from stefan123t/main
Raspberry Pi pyRF24 build instructions from mslookup
This commit is contained in:
commit
425ffdfc58
11 changed files with 199 additions and 77 deletions
14
README.md
14
README.md
|
@ -5,13 +5,13 @@ Various tools, examples, and documentation for communicating with Hoymiles micro
|
||||||
|
|
||||||
In particular:
|
In particular:
|
||||||
|
|
||||||
* `doc/hoymiles-format-description.txt` is a detailed description of the communications format and the history of this project
|
* `doc/hoymiles-format-description.txt` is a [detailed description of the communications format](doc/hoymiles-format-description.md) and the history of this project
|
||||||
* `doc/getting-started-ESP8266.md` shows the hardware setup for an ESP8266-based system
|
* `doc/getting-started-ESP8266.md` shows the [hardware setup for an ESP8266-based system](doc/getting-started-ESP8266.md)
|
||||||
* The `tools` folder contains various software tools for RaspberryPi, Arduino and ESP8266/ESP32:
|
* The `tools` folder contains various software tools for RaspberryPi, Arduino and ESP8266/ESP32:
|
||||||
* A [version for ESP8266](tools/esp8266) that includes a web interface
|
* A [version for ESP8266](tools/esp8266/) that includes an web interface
|
||||||
* A [version for Arduino Nano](tools/nano/NRF24_SendRcv)
|
* A [version for Arduino Nano](tools/nano/NRF24_SendRcv/)
|
||||||
* An [alternative Version of the above](tools/NRF24_SendRcv)
|
* An [alternative Version of the above](tools/NRF24_SendRcv/)
|
||||||
* A [different implementation](tools/HoyDtuSim)
|
* A [different implementation](tools/HoyDtuSim/)
|
||||||
* An [implementation for Raspberry Pi](tools/rpi) that polls an inverter and archives results as log files/stdout as well as posting them to an MQTT broker.
|
* An [implementation for Raspberry Pi](tools/rpi/) that polls an inverter and archives results as log files/stdout as well as posting them to an MQTT broker.
|
||||||
|
|
||||||
Contributors are always welcome!
|
Contributors are always welcome!
|
||||||
|
|
|
@ -12,7 +12,9 @@
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
app::app() : Main() {
|
app::app() : Main() {
|
||||||
|
#ifdef DEBUG_APP
|
||||||
DPRINTLN(F("app::app():Main"));
|
DPRINTLN(F("app::app():Main"));
|
||||||
|
#endif
|
||||||
mSendTicker = 0xffff;
|
mSendTicker = 0xffff;
|
||||||
mSendInterval = 0;
|
mSendInterval = 0;
|
||||||
mMqttTicker = 0xffff;
|
mMqttTicker = 0xffff;
|
||||||
|
@ -49,7 +51,9 @@ app::~app(void) {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::setup(uint32_t timeout) {
|
void app::setup(uint32_t timeout) {
|
||||||
|
#ifdef DEBUG_APP
|
||||||
DPRINTLN(F("app::setup"));
|
DPRINTLN(F("app::setup"));
|
||||||
|
#endif
|
||||||
Main::setup(timeout);
|
Main::setup(timeout);
|
||||||
|
|
||||||
mWeb->on("/", std::bind(&app::showIndex, this));
|
mWeb->on("/", std::bind(&app::showIndex, this));
|
||||||
|
@ -193,9 +197,11 @@ void app::setup(uint32_t timeout) {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::loop(void) {
|
void app::loop(void) {
|
||||||
|
#ifdef DEBUG_APP
|
||||||
//DPRINT(F("a"));
|
//DPRINT(F("a"));
|
||||||
//DPRINTLN(F("a"));
|
//DPRINTLN(F("a"));
|
||||||
//app_loops++;
|
//app_loops++;
|
||||||
|
#ifdef DEBUG_APP
|
||||||
Main::loop();
|
Main::loop();
|
||||||
|
|
||||||
mSys->Radio.loop();
|
mSys->Radio.loop();
|
||||||
|
@ -203,9 +209,11 @@ void app::loop(void) {
|
||||||
yield();
|
yield();
|
||||||
|
|
||||||
if(checkTicker(&mRxTicker, 5)) {
|
if(checkTicker(&mRxTicker, 5)) {
|
||||||
|
#ifdef DEBUG_APP
|
||||||
//DPRINTLN(F("app_loops =") + String(app_loops));
|
//DPRINTLN(F("app_loops =") + String(app_loops));
|
||||||
//app_loops=0;
|
//app_loops=0;
|
||||||
//DPRINT(F("a"));
|
//DPRINT(F("a"));
|
||||||
|
#endif
|
||||||
bool rxRdy = mSys->Radio.switchRxCh();
|
bool rxRdy = mSys->Radio.switchRxCh();
|
||||||
|
|
||||||
if(!mSys->BufCtrl.empty()) {
|
if(!mSys->BufCtrl.empty()) {
|
||||||
|
@ -355,14 +363,18 @@ void app::loop(void) {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::handleIntr(void) {
|
void app::handleIntr(void) {
|
||||||
|
#ifdef DEBUG_APP
|
||||||
//DPRINTLN(F("app::handleIntr"));
|
//DPRINTLN(F("app::handleIntr"));
|
||||||
|
#endif
|
||||||
mSys->Radio.handleIntr();
|
mSys->Radio.handleIntr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
bool app::buildPayload(uint8_t id) {
|
bool app::buildPayload(uint8_t id) {
|
||||||
|
#ifdef DEBUG_APP
|
||||||
//DPRINTLN(F("app::buildPayload"));
|
//DPRINTLN(F("app::buildPayload"));
|
||||||
|
#endif
|
||||||
uint16_t crc = 0xffff, crcRcv;
|
uint16_t crc = 0xffff, crcRcv;
|
||||||
if(mPayload[id].maxPackId > MAX_PAYLOAD_ENTRIES)
|
if(mPayload[id].maxPackId > MAX_PAYLOAD_ENTRIES)
|
||||||
mPayload[id].maxPackId = MAX_PAYLOAD_ENTRIES;
|
mPayload[id].maxPackId = MAX_PAYLOAD_ENTRIES;
|
||||||
|
@ -387,8 +399,10 @@ bool app::buildPayload(uint8_t id) {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::processPayload(bool retransmit) {
|
void app::processPayload(bool retransmit) {
|
||||||
|
#ifdef DEBUG_APP
|
||||||
//DPRINTLN(F("app::processPayload"));
|
//DPRINTLN(F("app::processPayload"));
|
||||||
//DPRINT(F("p"));
|
//DPRINT(F("p"));
|
||||||
|
#endif
|
||||||
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
|
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
|
||||||
Inverter<> *iv = mSys->getInverterByPos(id);
|
Inverter<> *iv = mSys->getInverterByPos(id);
|
||||||
if(NULL != iv) {
|
if(NULL != iv) {
|
||||||
|
@ -454,7 +468,9 @@ void app::processPayload(bool retransmit) {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::showIndex(void) {
|
void app::showIndex(void) {
|
||||||
|
#ifdef DEBUG_APP
|
||||||
DPRINTLN(F("app::showIndex"));
|
DPRINTLN(F("app::showIndex"));
|
||||||
|
#endif
|
||||||
String html = FPSTR(index_html);
|
String html = FPSTR(index_html);
|
||||||
html.replace(F("{DEVICE}"), mDeviceName);
|
html.replace(F("{DEVICE}"), mDeviceName);
|
||||||
html.replace(F("{VERSION}"), mVersion);
|
html.replace(F("{VERSION}"), mVersion);
|
||||||
|
@ -466,7 +482,9 @@ void app::showIndex(void) {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::showSetup(void) {
|
void app::showSetup(void) {
|
||||||
|
#ifdef DEBUG_APP
|
||||||
DPRINTLN(F("app::showSetup"));
|
DPRINTLN(F("app::showSetup"));
|
||||||
|
#endif
|
||||||
// overrides same method in main.cpp
|
// overrides same method in main.cpp
|
||||||
|
|
||||||
uint16_t interval;
|
uint16_t interval;
|
||||||
|
@ -586,14 +604,18 @@ void app::showSetup(void) {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::showSave(void) {
|
void app::showSave(void) {
|
||||||
|
#ifdef DEBUG_APP
|
||||||
DPRINTLN(F("app::showSave"));
|
DPRINTLN(F("app::showSave"));
|
||||||
|
#endif
|
||||||
saveValues(true);
|
saveValues(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::showErase() {
|
void app::showErase() {
|
||||||
|
#ifdef DEBUG_APP
|
||||||
DPRINTLN(F("app::showErase"));
|
DPRINTLN(F("app::showErase"));
|
||||||
|
#endif
|
||||||
eraseSettings();
|
eraseSettings();
|
||||||
showReboot();
|
showReboot();
|
||||||
}
|
}
|
||||||
|
@ -601,7 +623,9 @@ void app::showErase() {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::showStatistics(void) {
|
void app::showStatistics(void) {
|
||||||
|
#ifdef DEBUG_APP
|
||||||
//DPRINTLN(F("app::showStatistics"));
|
//DPRINTLN(F("app::showStatistics"));
|
||||||
|
#endif
|
||||||
String content = F("Receive success: ") + String(mRxSuccess) + "\n";
|
String content = F("Receive success: ") + String(mRxSuccess) + "\n";
|
||||||
content += F("Receive fail: ") + String(mRxFailed) + "\n";
|
content += F("Receive fail: ") + String(mRxFailed) + "\n";
|
||||||
content += F("Frames received: ") + String(mFrameCnt) + "\n";
|
content += F("Frames received: ") + String(mFrameCnt) + "\n";
|
||||||
|
@ -649,7 +673,9 @@ void app::showStatistics(void) {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::showHoymiles(void) {
|
void app::showHoymiles(void) {
|
||||||
|
#ifdef DEBUG_APP
|
||||||
DPRINTLN(F("app::showHoymiles"));
|
DPRINTLN(F("app::showHoymiles"));
|
||||||
|
#endif
|
||||||
String html = FPSTR(hoymiles_html);
|
String html = FPSTR(hoymiles_html);
|
||||||
html.replace(F("{DEVICE}"), mDeviceName);
|
html.replace(F("{DEVICE}"), mDeviceName);
|
||||||
html.replace(F("{VERSION}"), mVersion);
|
html.replace(F("{VERSION}"), mVersion);
|
||||||
|
@ -661,7 +687,9 @@ void app::showHoymiles(void) {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::showLiveData(void) {
|
void app::showLiveData(void) {
|
||||||
|
#ifdef DEBUG_APP
|
||||||
//DPRINTLN(F("app::showLiveData"));
|
//DPRINTLN(F("app::showLiveData"));
|
||||||
|
#endif
|
||||||
String modHtml;
|
String modHtml;
|
||||||
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
|
for(uint8_t id = 0; id < mSys->getNumInverters(); id++) {
|
||||||
Inverter<> *iv = mSys->getInverterByPos(id);
|
Inverter<> *iv = mSys->getInverterByPos(id);
|
||||||
|
@ -739,7 +767,9 @@ void app::showLiveData(void) {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::saveValues(bool webSend = true) {
|
void app::saveValues(bool webSend = true) {
|
||||||
|
#ifdef DEBUG_APP
|
||||||
DPRINTLN(F("app::saveValues"));
|
DPRINTLN(F("app::saveValues"));
|
||||||
|
#endif
|
||||||
Main::saveValues(false); // general configuration
|
Main::saveValues(false); // general configuration
|
||||||
|
|
||||||
if(mWeb->args() > 0) {
|
if(mWeb->args() > 0) {
|
||||||
|
@ -848,7 +878,9 @@ void app::saveValues(bool webSend = true) {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::updateCrc(void) {
|
void app::updateCrc(void) {
|
||||||
|
#ifdef DEBUG_APP
|
||||||
DPRINTLN(F("app::updateCrc"));
|
DPRINTLN(F("app::updateCrc"));
|
||||||
|
#endif
|
||||||
Main::updateCrc();
|
Main::updateCrc();
|
||||||
|
|
||||||
uint16_t crc;
|
uint16_t crc;
|
||||||
|
|
|
@ -16,6 +16,12 @@
|
||||||
#include "hmSystem.h"
|
#include "hmSystem.h"
|
||||||
#include "mqtt.h"
|
#include "mqtt.h"
|
||||||
|
|
||||||
|
#ifdef DEBUG_APP
|
||||||
|
#define DBGAPP(f,...) do { Serial.printf(PSTR(f), ##__VA_ARGS__); } while (0)
|
||||||
|
#else
|
||||||
|
#define DBGAPP(x...) do { (void)0; } while (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef CircularBuffer<packet_t, PACKET_BUFFER_SIZE> BufferType;
|
typedef CircularBuffer<packet_t, PACKET_BUFFER_SIZE> BufferType;
|
||||||
typedef HmRadio<RF24_CE_PIN, RF24_CS_PIN, RF24_IRQ_PIN, BufferType> RadioType;
|
typedef HmRadio<RF24_CE_PIN, RF24_CS_PIN, RF24_IRQ_PIN, BufferType> RadioType;
|
||||||
typedef Inverter<float> InverterType;
|
typedef Inverter<float> InverterType;
|
||||||
|
|
|
@ -58,4 +58,11 @@
|
||||||
// changes the style of "/setup" page, visualized = nicer
|
// changes the style of "/setup" page, visualized = nicer
|
||||||
#define LIVEDATA_VISUALIZED
|
#define LIVEDATA_VISUALIZED
|
||||||
|
|
||||||
|
// comment out to disable any of the debug options here
|
||||||
|
#define DEBUG_APP
|
||||||
|
#define DEBUG_HMINVERTER
|
||||||
|
#define DEBUG_HMRADIO
|
||||||
|
#define DEBUG_HMSYSTEM
|
||||||
|
#define DEBUG_HMMAIN
|
||||||
|
|
||||||
#endif /*__CONFIG_H__*/
|
#endif /*__CONFIG_H__*/
|
||||||
|
|
|
@ -92,10 +92,16 @@ typedef struct {
|
||||||
#define ADDR_SER_INTERVAL ADDR_SER_DEBUG + SER_DEBUG_LEN
|
#define ADDR_SER_INTERVAL ADDR_SER_DEBUG + SER_DEBUG_LEN
|
||||||
#define ADDR_NEXT ADDR_SER_INTERVAL + SER_INTERVAL_LEN
|
#define ADDR_NEXT ADDR_SER_INTERVAL + SER_INTERVAL_LEN
|
||||||
|
|
||||||
#define ADDR_SETTINGS_CRC 950
|
// #define ADDR_SETTINGS_CRC 950
|
||||||
|
#define ADDR_SETTINGS_CRC ADDR_NEXT + CRC_LEN
|
||||||
|
|
||||||
#if(ADDR_SETTINGS_CRC <= ADDR_NEXT)
|
#if(ADDR_SETTINGS_CRC <= ADDR_NEXT)
|
||||||
#error address overlap!
|
#pragma error "address overlap! (ADDR_SETTINGS_CRC="+ ADDR_SETTINGS_CRC +", ADDR_NEXT="+ ADDR_NEXT +")"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if(ADDR_SETTINGS_CRC >= 4096 - CRC_LEN)
|
||||||
|
#pragma error "EEPROM size exceeded! (ADDR_SETTINGS_CRC="+ ADDR_SETTINGS_CRC +", CRC_LEN="+ CRC_LEN +")"
|
||||||
|
#pragma error "Configure less inverters? (MAX_NUM_INVERTERS=" + MAX_NUM_INVERTERS +")"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*__DEFINES_H__*/
|
#endif /*__DEFINES_H__*/
|
||||||
|
|
|
@ -8,6 +8,12 @@
|
||||||
|
|
||||||
#include "hmDefines.h"
|
#include "hmDefines.h"
|
||||||
|
|
||||||
|
#ifdef DEBUG_HMINVERTER
|
||||||
|
#define DBGINV(f,...) do { Serial.printf(PSTR(f), ##__VA_ARGS__); } while (0)
|
||||||
|
#else
|
||||||
|
#define DBGINV(x...) do { (void)0; } while (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For values which are of interest and not transmitted by the inverter can be
|
* For values which are of interest and not transmitted by the inverter can be
|
||||||
* calculated automatically.
|
* calculated automatically.
|
||||||
|
@ -86,7 +92,7 @@ class Inverter {
|
||||||
}
|
}
|
||||||
|
|
||||||
void init(void) {
|
void init(void) {
|
||||||
DPRINTLN(F("hmInverter.h:init"));
|
DBGINV(F("hmInverter.h:init"));
|
||||||
getAssignment();
|
getAssignment();
|
||||||
toRadioId();
|
toRadioId();
|
||||||
record = new RECORDTYPE[listLen];
|
record = new RECORDTYPE[listLen];
|
||||||
|
@ -96,7 +102,7 @@ class Inverter {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t getPosByChFld(uint8_t channel, uint8_t fieldId) {
|
uint8_t getPosByChFld(uint8_t channel, uint8_t fieldId) {
|
||||||
//DPRINTLN(F("hmInverter.h:getPosByChFld"));
|
//DBGINV(F("hmInverter.h:getPosByChFld"));
|
||||||
uint8_t pos = 0;
|
uint8_t pos = 0;
|
||||||
for(; pos < listLen; pos++) {
|
for(; pos < listLen; pos++) {
|
||||||
if((assign[pos].ch == channel) && (assign[pos].fieldId == fieldId))
|
if((assign[pos].ch == channel) && (assign[pos].fieldId == fieldId))
|
||||||
|
@ -106,22 +112,22 @@ class Inverter {
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *getFieldName(uint8_t pos) {
|
const char *getFieldName(uint8_t pos) {
|
||||||
//DPRINTLN(F("hmInverter.h:getFieldName"));
|
//DBGINV(F("hmInverter.h:getFieldName"));
|
||||||
return fields[assign[pos].fieldId];
|
return fields[assign[pos].fieldId];
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *getUnit(uint8_t pos) {
|
const char *getUnit(uint8_t pos) {
|
||||||
//DPRINTLN(F("hmInverter.h:getUnit"));
|
//DBGINV(F("hmInverter.h:getUnit"));
|
||||||
return units[assign[pos].unitId];
|
return units[assign[pos].unitId];
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t getChannel(uint8_t pos) {
|
uint8_t getChannel(uint8_t pos) {
|
||||||
//DPRINTLN(F("hmInverter.h:getChannel"));
|
//DBGINV(F("hmInverter.h:getChannel"));
|
||||||
return assign[pos].ch;
|
return assign[pos].ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addValue(uint8_t pos, uint8_t buf[]) {
|
void addValue(uint8_t pos, uint8_t buf[]) {
|
||||||
//DPRINTLN(F("hmInverter.h:addValue"));
|
//DBGINV(F("hmInverter.h:addValue"));
|
||||||
uint8_t ptr = assign[pos].start;
|
uint8_t ptr = assign[pos].start;
|
||||||
uint8_t end = ptr + assign[pos].num;
|
uint8_t end = ptr + assign[pos].num;
|
||||||
uint16_t div = assign[pos].div;
|
uint16_t div = assign[pos].div;
|
||||||
|
@ -138,12 +144,12 @@ class Inverter {
|
||||||
}
|
}
|
||||||
|
|
||||||
RECORDTYPE getValue(uint8_t pos) {
|
RECORDTYPE getValue(uint8_t pos) {
|
||||||
//DPRINTLN(F("hmInverter.h:getValue"));
|
//DBGINV(F("hmInverter.h:getValue"));
|
||||||
return record[pos];
|
return record[pos];
|
||||||
}
|
}
|
||||||
|
|
||||||
void doCalculations(void) {
|
void doCalculations(void) {
|
||||||
//DPRINTLN(F("hmInverter.h:doCalculations"));
|
//DBGINV(F("hmInverter.h:doCalculations"));
|
||||||
for(uint8_t i = 0; i < listLen; i++) {
|
for(uint8_t i = 0; i < listLen; i++) {
|
||||||
if(CMD_CALC == assign[i].div) {
|
if(CMD_CALC == assign[i].div) {
|
||||||
record[i] = calcFunctions<RECORDTYPE>[assign[i].start].func(this, assign[i].num);
|
record[i] = calcFunctions<RECORDTYPE>[assign[i].start].func(this, assign[i].num);
|
||||||
|
@ -153,12 +159,12 @@ class Inverter {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isAvailable(uint32_t timestamp) {
|
bool isAvailable(uint32_t timestamp) {
|
||||||
//DPRINTLN(F("hmInverter.h:isAvailable"));
|
//DBGINV(F("hmInverter.h:isAvailable"));
|
||||||
return ((timestamp - ts) < INACT_THRES_SEC);
|
return ((timestamp - ts) < INACT_THRES_SEC);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isProducing(uint32_t timestamp) {
|
bool isProducing(uint32_t timestamp) {
|
||||||
//DPRINTLN(F("hmInverter.h:isProducing"));
|
//DBGINV(F("hmInverter.h:isProducing"));
|
||||||
if(isAvailable(timestamp)) {
|
if(isAvailable(timestamp)) {
|
||||||
uint8_t pos = getPosByChFld(CH0, FLD_PAC);
|
uint8_t pos = getPosByChFld(CH0, FLD_PAC);
|
||||||
return (getValue(pos) > INACT_PWR_THRESH);
|
return (getValue(pos) > INACT_PWR_THRESH);
|
||||||
|
@ -167,13 +173,13 @@ class Inverter {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t getLastTs(void) {
|
uint32_t getLastTs(void) {
|
||||||
//DPRINTLN(F("hmInverter.h:getLastTs"));
|
//DBGINV(F("hmInverter.h:getLastTs"));
|
||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void toRadioId(void) {
|
void toRadioId(void) {
|
||||||
//DPRINTLN(F("hmInverter.h:toRadioId"));
|
//DBGINV(F("hmInverter.h:toRadioId"));
|
||||||
radioId.u64 = 0ULL;
|
radioId.u64 = 0ULL;
|
||||||
radioId.b[4] = serial.b[0];
|
radioId.b[4] = serial.b[0];
|
||||||
radioId.b[3] = serial.b[1];
|
radioId.b[3] = serial.b[1];
|
||||||
|
@ -183,7 +189,7 @@ class Inverter {
|
||||||
}
|
}
|
||||||
|
|
||||||
void getAssignment(void) {
|
void getAssignment(void) {
|
||||||
//DPRINTLN(F("hmInverter.h:getAssignment"));
|
//DBGINV(F("hmInverter.h:getAssignment"));
|
||||||
if(INV_TYPE_1CH == type) {
|
if(INV_TYPE_1CH == type) {
|
||||||
listLen = (uint8_t)(HM1CH_LIST_LEN);
|
listLen = (uint8_t)(HM1CH_LIST_LEN);
|
||||||
assign = (byteAssign_t*)hm1chAssignment;
|
assign = (byteAssign_t*)hm1chAssignment;
|
||||||
|
@ -216,7 +222,7 @@ class Inverter {
|
||||||
|
|
||||||
template<class T=float>
|
template<class T=float>
|
||||||
static T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0) {
|
static T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0) {
|
||||||
//DPRINTLN(F("hmInverter.h:calcYieldTotalCh0"));
|
//DBGINV(F("hmInverter.h:calcYieldTotalCh0"));
|
||||||
if(NULL != iv) {
|
if(NULL != iv) {
|
||||||
T yield = 0;
|
T yield = 0;
|
||||||
for(uint8_t i = 1; i <= iv->channels; i++) {
|
for(uint8_t i = 1; i <= iv->channels; i++) {
|
||||||
|
@ -230,7 +236,7 @@ static T calcYieldTotalCh0(Inverter<> *iv, uint8_t arg0) {
|
||||||
|
|
||||||
template<class T=float>
|
template<class T=float>
|
||||||
static T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0) {
|
static T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0) {
|
||||||
//DPRINTLN(F("hmInverter.h:calcYieldDayCh0"));
|
//DBGINV(F("hmInverter.h:calcYieldDayCh0"));
|
||||||
if(NULL != iv) {
|
if(NULL != iv) {
|
||||||
T yield = 0;
|
T yield = 0;
|
||||||
for(uint8_t i = 1; i <= iv->channels; i++) {
|
for(uint8_t i = 1; i <= iv->channels; i++) {
|
||||||
|
@ -244,7 +250,7 @@ static T calcYieldDayCh0(Inverter<> *iv, uint8_t arg0) {
|
||||||
|
|
||||||
template<class T=float>
|
template<class T=float>
|
||||||
static T calcUdcCh(Inverter<> *iv, uint8_t arg0) {
|
static T calcUdcCh(Inverter<> *iv, uint8_t arg0) {
|
||||||
//DPRINTLN(F("hmInverter.h:calcUdcCh"));
|
//DBGINV(F("hmInverter.h:calcUdcCh"));
|
||||||
// arg0 = channel of source
|
// arg0 = channel of source
|
||||||
for(uint8_t i = 0; i < iv->listLen; i++) {
|
for(uint8_t i = 0; i < iv->listLen; i++) {
|
||||||
if((FLD_UDC == iv->assign[i].fieldId) && (arg0 == iv->assign[i].ch)) {
|
if((FLD_UDC == iv->assign[i].fieldId) && (arg0 == iv->assign[i].ch)) {
|
||||||
|
@ -257,7 +263,7 @@ static T calcUdcCh(Inverter<> *iv, uint8_t arg0) {
|
||||||
|
|
||||||
template<class T=float>
|
template<class T=float>
|
||||||
static T calcPowerDcCh0(Inverter<> *iv, uint8_t arg0) {
|
static T calcPowerDcCh0(Inverter<> *iv, uint8_t arg0) {
|
||||||
//DPRINTLN(F("hmInverter.h:calcPowerDcCh0"));
|
//DBGINV(F("hmInverter.h:calcPowerDcCh0"));
|
||||||
if(NULL != iv) {
|
if(NULL != iv) {
|
||||||
T dcPower = 0;
|
T dcPower = 0;
|
||||||
for(uint8_t i = 1; i <= iv->channels; i++) {
|
for(uint8_t i = 1; i <= iv->channels; i++) {
|
||||||
|
@ -271,7 +277,7 @@ static T calcPowerDcCh0(Inverter<> *iv, uint8_t arg0) {
|
||||||
|
|
||||||
template<class T=float>
|
template<class T=float>
|
||||||
static T calcEffiencyCh0(Inverter<> *iv, uint8_t arg0) {
|
static T calcEffiencyCh0(Inverter<> *iv, uint8_t arg0) {
|
||||||
//DPRINTLN(F("hmInverter.h:calcEfficiencyCh0"));
|
//DBGINV(F("hmInverter.h:calcEfficiencyCh0"));
|
||||||
if(NULL != iv) {
|
if(NULL != iv) {
|
||||||
uint8_t pos = iv->getPosByChFld(CH0, FLD_PAC);
|
uint8_t pos = iv->getPosByChFld(CH0, FLD_PAC);
|
||||||
T acPower = iv->getValue(pos);
|
T acPower = iv->getValue(pos);
|
||||||
|
@ -288,7 +294,7 @@ static T calcEffiencyCh0(Inverter<> *iv, uint8_t arg0) {
|
||||||
|
|
||||||
template<class T=float>
|
template<class T=float>
|
||||||
static T calcIrradiation(Inverter<> *iv, uint8_t arg0) {
|
static T calcIrradiation(Inverter<> *iv, uint8_t arg0) {
|
||||||
//DPRINTLN(F("hmInverter.h:calcIrradiation"));
|
//DBGINV(F("hmInverter.h:calcIrradiation"));
|
||||||
// arg0 = channel
|
// arg0 = channel
|
||||||
if(NULL != iv) {
|
if(NULL != iv) {
|
||||||
uint8_t pos = iv->getPosByChFld(arg0, FLD_PDC);
|
uint8_t pos = iv->getPosByChFld(arg0, FLD_PDC);
|
||||||
|
|
|
@ -22,6 +22,12 @@
|
||||||
#define RX_LOOP_CNT 300
|
#define RX_LOOP_CNT 300
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef DEBUG_HMRADIO
|
||||||
|
#define DBGHMR(f,...) do { Serial.printf(PSTR(f), ##__VA_ARGS__); } while (0)
|
||||||
|
#else
|
||||||
|
#define DBGHMR(x...) do { (void)0; } while (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
const char* const rf24AmpPower[] = {"MIN", "LOW", "HIGH", "MAX"};
|
const char* const rf24AmpPower[] = {"MIN", "LOW", "HIGH", "MAX"};
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,7 +60,7 @@ template <uint8_t CE_PIN, uint8_t CS_PIN, uint8_t IRQ_PIN, class BUFFER, uint64_
|
||||||
class HmRadio {
|
class HmRadio {
|
||||||
public:
|
public:
|
||||||
HmRadio() : mNrf24(CE_PIN, CS_PIN, SPI_SPEED) {
|
HmRadio() : mNrf24(CE_PIN, CS_PIN, SPI_SPEED) {
|
||||||
DPRINTLN(F("hmRadio.h : HmRadio():mNrf24(CE_PIN: ") + String(CE_PIN) + F(", CS_PIN: ") + String(CS_PIN) + F(", SPI_SPEED: ") + String(SPI_SPEED) + ")");
|
DBGHMR(F("hmRadio.h : HmRadio():mNrf24(CE_PIN: ") + String(CE_PIN) + F(", CS_PIN: ") + String(CS_PIN) + F(", SPI_SPEED: ") + String(SPI_SPEED) + ")");
|
||||||
mTxChLst[0] = 40;
|
mTxChLst[0] = 40;
|
||||||
//mTxChIdx = 1;
|
//mTxChIdx = 1;
|
||||||
|
|
||||||
|
@ -81,7 +87,7 @@ class HmRadio {
|
||||||
~HmRadio() {}
|
~HmRadio() {}
|
||||||
|
|
||||||
void setup(BUFFER *ctrl) {
|
void setup(BUFFER *ctrl) {
|
||||||
DPRINTLN(F("hmRadio.h:setup"));
|
DBGHMR(F("hmRadio.h:setup"));
|
||||||
pinMode(pinIrq, INPUT_PULLUP);
|
pinMode(pinIrq, INPUT_PULLUP);
|
||||||
|
|
||||||
mBufCtrl = ctrl;
|
mBufCtrl = ctrl;
|
||||||
|
@ -147,12 +153,12 @@ class HmRadio {
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleIntr(void) {
|
void handleIntr(void) {
|
||||||
//DPRINTLN(F("hmRadio.h:handleIntr"));
|
//DBGHMR(F("hmRadio.h:handleIntr"));
|
||||||
mIrqRcvd = true;
|
mIrqRcvd = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t getDefaultChannel(void) {
|
uint8_t getDefaultChannel(void) {
|
||||||
//DPRINTLN(F("hmRadio.h:getDefaultChannel"));
|
//DBGHMR(F("hmRadio.h:getDefaultChannel"));
|
||||||
return mTxChLst[0];
|
return mTxChLst[0];
|
||||||
}
|
}
|
||||||
/*uint8_t getLastChannel(void) {
|
/*uint8_t getLastChannel(void) {
|
||||||
|
@ -166,7 +172,7 @@ class HmRadio {
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
void sendTimePacket(uint64_t invId, uint32_t ts) {
|
void sendTimePacket(uint64_t invId, uint32_t ts) {
|
||||||
//DPRINTLN(F("hmRadio.h:sendTimePacket"));
|
//DBGHMR(F("hmRadio.h:sendTimePacket"));
|
||||||
sendCmdPacket(invId, 0x15, 0x80, false);
|
sendCmdPacket(invId, 0x15, 0x80, false);
|
||||||
mTxBuf[10] = 0x0b; // cid
|
mTxBuf[10] = 0x0b; // cid
|
||||||
mTxBuf[11] = 0x00;
|
mTxBuf[11] = 0x00;
|
||||||
|
@ -182,7 +188,7 @@ class HmRadio {
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendCmdPacket(uint64_t invId, uint8_t mid, uint8_t pid, bool calcCrc = true) {
|
void sendCmdPacket(uint64_t invId, uint8_t mid, uint8_t pid, bool calcCrc = true) {
|
||||||
//DPRINTLN(F("hmRadio.h:sendCmdPacket"));
|
//DBGHMR(F("hmRadio.h:sendCmdPacket"));
|
||||||
memset(mTxBuf, 0, MAX_RF_PAYLOAD_SIZE);
|
memset(mTxBuf, 0, MAX_RF_PAYLOAD_SIZE);
|
||||||
mTxBuf[0] = mid; // message id
|
mTxBuf[0] = mid; // message id
|
||||||
CP_U32_BigEndian(&mTxBuf[1], (invId >> 8));
|
CP_U32_BigEndian(&mTxBuf[1], (invId >> 8));
|
||||||
|
@ -195,7 +201,7 @@ class HmRadio {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool checkPaketCrc(uint8_t buf[], uint8_t *len, uint8_t rxCh) {
|
bool checkPaketCrc(uint8_t buf[], uint8_t *len, uint8_t rxCh) {
|
||||||
//DPRINTLN(F("hmRadio.h:checkPaketCrc"));
|
//DBGHMR(F("hmRadio.h:checkPaketCrc"));
|
||||||
*len = (buf[0] >> 2);
|
*len = (buf[0] >> 2);
|
||||||
if(*len > (MAX_RF_PAYLOAD_SIZE - 2))
|
if(*len > (MAX_RF_PAYLOAD_SIZE - 2))
|
||||||
*len = MAX_RF_PAYLOAD_SIZE - 2;
|
*len = MAX_RF_PAYLOAD_SIZE - 2;
|
||||||
|
@ -210,8 +216,8 @@ class HmRadio {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool switchRxCh(uint16_t addLoop = 0) {
|
bool switchRxCh(uint16_t addLoop = 0) {
|
||||||
//DPRINTLN(F("hmRadio.h:switchRxCh"));
|
//DBGHMR(F("hmRadio.h:switchRxCh"));
|
||||||
//DPRINT(F("R"));
|
//DBGHMR(F("R"));
|
||||||
|
|
||||||
mRxLoopCnt += addLoop;
|
mRxLoopCnt += addLoop;
|
||||||
if(mRxLoopCnt != 0) {
|
if(mRxLoopCnt != 0) {
|
||||||
|
@ -226,7 +232,7 @@ class HmRadio {
|
||||||
}
|
}
|
||||||
|
|
||||||
void dumpBuf(const char *info, uint8_t buf[], uint8_t len) {
|
void dumpBuf(const char *info, uint8_t buf[], uint8_t len) {
|
||||||
//DPRINTLN(F("hmRadio.h:dumpBuf"));
|
//DBGHMR(F("hmRadio.h:dumpBuf"));
|
||||||
if(NULL != info)
|
if(NULL != info)
|
||||||
DPRINT(String(info));
|
DPRINT(String(info));
|
||||||
for(uint8_t i = 0; i < len; i++) {
|
for(uint8_t i = 0; i < len; i++) {
|
||||||
|
@ -237,7 +243,7 @@ class HmRadio {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isChipConnected(void) {
|
bool isChipConnected(void) {
|
||||||
//DPRINTLN(F("hmRadio.h:isChipConnected"));
|
//DBGHMR(F("hmRadio.h:isChipConnected"));
|
||||||
return mNrf24.isChipConnected();
|
return mNrf24.isChipConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,8 +258,8 @@ class HmRadio {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void sendPacket(uint64_t invId, uint8_t buf[], uint8_t len, bool clear=false) {
|
void sendPacket(uint64_t invId, uint8_t buf[], uint8_t len, bool clear=false) {
|
||||||
//DPRINTLN(F("hmRadio.h:sendPacket"));
|
//DBGHMR(F("hmRadio.h:sendPacket"));
|
||||||
//DPRINTLN("sent packet: #" + String(mSendCnt));
|
//DBGHMR("sent packet: #" + String(mSendCnt));
|
||||||
//dumpBuf("SEN ", buf, len);
|
//dumpBuf("SEN ", buf, len);
|
||||||
if(mSerialDebug) {
|
if(mSerialDebug) {
|
||||||
DPRINT("Transmit " + String(len) + " | ");
|
DPRINT("Transmit " + String(len) + " | ");
|
||||||
|
|
|
@ -11,7 +11,11 @@
|
||||||
#include "hmRadio.h"
|
#include "hmRadio.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEBUG_HMSYSTEM
|
||||||
|
#define DBGHMS(f,...) do { Serial.printf(PSTR(f), ##__VA_ARGS__); } while (0)
|
||||||
|
#else
|
||||||
|
#define DBGHMS(x...) do { (void)0; } while (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
template <class RADIO, class BUFFER, uint8_t MAX_INVERTER=3, class INVERTERTYPE=Inverter<float>>
|
template <class RADIO, class BUFFER, uint8_t MAX_INVERTER=3, class INVERTERTYPE=Inverter<float>>
|
||||||
class HmSystem {
|
class HmSystem {
|
||||||
|
@ -29,12 +33,12 @@ class HmSystem {
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
DPRINTLN(F("hmSystem.h:setup"));
|
DBGHMS(F("hmSystem.h:setup"));
|
||||||
Radio.setup(&BufCtrl);
|
Radio.setup(&BufCtrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
INVERTERTYPE *addInverter(const char *name, uint64_t serial, uint16_t chMaxPwr[]) {
|
INVERTERTYPE *addInverter(const char *name, uint64_t serial, uint16_t chMaxPwr[]) {
|
||||||
DPRINTLN(F("hmSystem.h:addInverter"));
|
DBGHMS(F("hmSystem.h:addInverter"));
|
||||||
if(MAX_INVERTER <= mNumInv) {
|
if(MAX_INVERTER <= mNumInv) {
|
||||||
DPRINT(F("max number of inverters reached!"));
|
DPRINT(F("max number of inverters reached!"));
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -71,7 +75,7 @@ class HmSystem {
|
||||||
}
|
}
|
||||||
|
|
||||||
INVERTERTYPE *findInverter(uint8_t buf[]) {
|
INVERTERTYPE *findInverter(uint8_t buf[]) {
|
||||||
//DPRINTLN(F("hmSystem.h:findInverter"));
|
//DBGHMS(F("hmSystem.h:findInverter"));
|
||||||
INVERTERTYPE *p;
|
INVERTERTYPE *p;
|
||||||
for(uint8_t i = 0; i < mNumInv; i++) {
|
for(uint8_t i = 0; i < mNumInv; i++) {
|
||||||
p = &mInverter[i];
|
p = &mInverter[i];
|
||||||
|
@ -85,7 +89,7 @@ class HmSystem {
|
||||||
}
|
}
|
||||||
|
|
||||||
INVERTERTYPE *getInverterByPos(uint8_t pos) {
|
INVERTERTYPE *getInverterByPos(uint8_t pos) {
|
||||||
//DPRINTLN(F("hmSystem.h:getInverterByPos"));
|
//DBGHMS(F("hmSystem.h:getInverterByPos"));
|
||||||
if(mInverter[pos].serial.u64 != 0ULL)
|
if(mInverter[pos].serial.u64 != 0ULL)
|
||||||
return &mInverter[pos];
|
return &mInverter[pos];
|
||||||
else
|
else
|
||||||
|
@ -93,7 +97,7 @@ class HmSystem {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t getNumInverters(void) {
|
uint8_t getNumInverters(void) {
|
||||||
//DPRINTLN(F("hmSystem.h:getNumInverters"));
|
//DBGHMS(F("hmSystem.h:getNumInverters"));
|
||||||
return mNumInv;
|
return mNumInv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ Main::Main(void) {
|
||||||
|
|
||||||
mEep = new eep();
|
mEep = new eep();
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
DPRINTLN(F("Main::Main"));
|
DBGMAIN(F("Main::Main"));
|
||||||
|
|
||||||
mUptimeSecs = 0;
|
mUptimeSecs = 0;
|
||||||
mUptimeTicker = 0xffffffff;
|
mUptimeTicker = 0xffffffff;
|
||||||
|
@ -45,7 +45,7 @@ Main::Main(void) {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void Main::setup(uint32_t timeout) {
|
void Main::setup(uint32_t timeout) {
|
||||||
DPRINTLN(F("Main::setup"));
|
DBGMAIN(F("Main::setup"));
|
||||||
bool startAp = mApActive;
|
bool startAp = mApActive;
|
||||||
mLimit = timeout;
|
mLimit = timeout;
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ void Main::setup(uint32_t timeout) {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void Main::loop(void) {
|
void Main::loop(void) {
|
||||||
//DPRINT(F("M"));
|
//DBGMAIN(F("M"));
|
||||||
if(mApActive) {
|
if(mApActive) {
|
||||||
mDns->processNextRequest();
|
mDns->processNextRequest();
|
||||||
#ifndef AP_ONLY
|
#ifndef AP_ONLY
|
||||||
|
@ -123,7 +123,7 @@ void Main::loop(void) {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
bool Main::getConfig(void) {
|
bool Main::getConfig(void) {
|
||||||
DPRINTLN(F("Main::getConfig"));
|
DBGMAIN(F("Main::getConfig"));
|
||||||
bool mApActive = false;
|
bool mApActive = false;
|
||||||
|
|
||||||
mWifiSettingsValid = checkEEpCrc(ADDR_START, ADDR_WIFI_CRC, ADDR_WIFI_CRC);
|
mWifiSettingsValid = checkEEpCrc(ADDR_START, ADDR_WIFI_CRC, ADDR_WIFI_CRC);
|
||||||
|
@ -146,7 +146,7 @@ bool Main::getConfig(void) {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void Main::setupAp(const char *ssid, const char *pwd) {
|
void Main::setupAp(const char *ssid, const char *pwd) {
|
||||||
DPRINTLN(F("Main::setupAp"));
|
DBGMAIN(F("Main::setupAp"));
|
||||||
IPAddress apIp(192, 168, 1, 1);
|
IPAddress apIp(192, 168, 1, 1);
|
||||||
|
|
||||||
DPRINTLN(F("\n---------\nAP MODE\nSSDI: ")
|
DPRINTLN(F("\n---------\nAP MODE\nSSDI: ")
|
||||||
|
@ -154,7 +154,7 @@ void Main::setupAp(const char *ssid, const char *pwd) {
|
||||||
+ String(pwd) + F("\nActive for: ")
|
+ String(pwd) + F("\nActive for: ")
|
||||||
+ String(WIFI_AP_ACTIVE_TIME) + F(" seconds")
|
+ String(WIFI_AP_ACTIVE_TIME) + F(" seconds")
|
||||||
+ F("\n---------\n"));
|
+ F("\n---------\n"));
|
||||||
DPRINTLN("DBG: " + String(mNextTryTs));
|
DBGMAIN("DBG: " + String(mNextTryTs));
|
||||||
|
|
||||||
WiFi.mode(WIFI_AP);
|
WiFi.mode(WIFI_AP);
|
||||||
WiFi.softAPConfig(apIp, apIp, IPAddress(255, 255, 255, 0));
|
WiFi.softAPConfig(apIp, apIp, IPAddress(255, 255, 255, 0));
|
||||||
|
@ -173,7 +173,7 @@ void Main::setupAp(const char *ssid, const char *pwd) {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
bool Main::setupStation(uint32_t timeout) {
|
bool Main::setupStation(uint32_t timeout) {
|
||||||
DPRINTLN(F("Main::setupStation"));
|
DBGMAIN(F("Main::setupStation"));
|
||||||
int32_t cnt;
|
int32_t cnt;
|
||||||
bool startAp = false;
|
bool startAp = false;
|
||||||
|
|
||||||
|
@ -223,7 +223,7 @@ bool Main::setupStation(uint32_t timeout) {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void Main::showSetup(void) {
|
void Main::showSetup(void) {
|
||||||
DPRINTLN(F("Main::showSetup"));
|
DBGMAIN(F("Main::showSetup"));
|
||||||
String html = FPSTR(setup_html);
|
String html = FPSTR(setup_html);
|
||||||
html.replace(F("{SSID}"), mStationSsid);
|
html.replace(F("{SSID}"), mStationSsid);
|
||||||
// PWD will be left at the default value (for protection)
|
// PWD will be left at the default value (for protection)
|
||||||
|
@ -241,21 +241,23 @@ void Main::showSetup(void) {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void Main::showCss(void) {
|
void Main::showCss(void) {
|
||||||
DPRINTLN(F("Main::showCss"));
|
DBGMAIN(F("Main::showCss"));
|
||||||
mWeb->send(200, "text/css", FPSTR(style_css));
|
mWeb->send(200, "text/css", FPSTR(style_css));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void Main::showSave(void) {
|
void Main::showSave(void) {
|
||||||
|
#ifdef DEBUG_HMMAIN
|
||||||
DPRINTLN(F("Main::showSave"));
|
DPRINTLN(F("Main::showSave"));
|
||||||
|
#endif
|
||||||
saveValues(true);
|
saveValues(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void Main::saveValues(bool webSend = true) {
|
void Main::saveValues(bool webSend = true) {
|
||||||
DPRINTLN(F("Main::saveValues"));
|
DBGMAIN(F("Main::saveValues"));
|
||||||
if(mWeb->args() > 0) {
|
if(mWeb->args() > 0) {
|
||||||
if(mWeb->arg("ssid") != "") {
|
if(mWeb->arg("ssid") != "") {
|
||||||
memset(mStationSsid, 0, SSID_LEN);
|
memset(mStationSsid, 0, SSID_LEN);
|
||||||
|
@ -289,7 +291,7 @@ void Main::saveValues(bool webSend = true) {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void Main::updateCrc(void) {
|
void Main::updateCrc(void) {
|
||||||
DPRINTLN(F("Main::updateCrc"));
|
DBGMAIN(F("Main::updateCrc"));
|
||||||
uint16_t crc;
|
uint16_t crc;
|
||||||
crc = buildEEpCrc(ADDR_START, ADDR_WIFI_CRC);
|
crc = buildEEpCrc(ADDR_START, ADDR_WIFI_CRC);
|
||||||
//Serial.println("new CRC: " + String(crc, HEX));
|
//Serial.println("new CRC: " + String(crc, HEX));
|
||||||
|
@ -300,7 +302,7 @@ void Main::updateCrc(void) {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void Main::showUptime(void) {
|
void Main::showUptime(void) {
|
||||||
//DPRINTLN(F("Main::showUptime"));
|
//DBGMAIN(F("Main::showUptime"));
|
||||||
char time[20] = {0};
|
char time[20] = {0};
|
||||||
|
|
||||||
int upTimeSc = uint32_t((mUptimeSecs) % 60);
|
int upTimeSc = uint32_t((mUptimeSecs) % 60);
|
||||||
|
@ -316,14 +318,14 @@ void Main::showUptime(void) {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void Main::showTime(void) {
|
void Main::showTime(void) {
|
||||||
//DPRINTLN(F("Main::showTime"));
|
//DBGMAIN(F("Main::showTime"));
|
||||||
mWeb->send(200, "text/plain", getDateTimeStr(mTimestamp));
|
mWeb->send(200, "text/plain", getDateTimeStr(mTimestamp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void Main::showNotFound(void) {
|
void Main::showNotFound(void) {
|
||||||
DPRINTLN(F("Main::showNotFound - ") + mWeb->uri());
|
DBGMAIN(F("Main::showNotFound - ") + mWeb->uri());
|
||||||
String msg = F("File Not Found\n\nURI: ");
|
String msg = F("File Not Found\n\nURI: ");
|
||||||
msg += mWeb->uri();
|
msg += mWeb->uri();
|
||||||
msg += F("\nMethod: ");
|
msg += F("\nMethod: ");
|
||||||
|
@ -342,7 +344,7 @@ void Main::showNotFound(void) {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void Main::showReboot(void) {
|
void Main::showReboot(void) {
|
||||||
DPRINTLN(F("Main::showReboot"));
|
DBGMAIN(F("Main::showReboot"));
|
||||||
mWeb->send(200, F("text/html"), F("<!doctype html><html><head><title>Rebooting ...</title><meta http-equiv=\"refresh\" content=\"10; URL=/\"></head><body>rebooting ... auto reload after 10s</body></html>"));
|
mWeb->send(200, F("text/html"), F("<!doctype html><html><head><title>Rebooting ...</title><meta http-equiv=\"refresh\" content=\"10; URL=/\"></head><body>rebooting ... auto reload after 10s</body></html>"));
|
||||||
delay(1000);
|
delay(1000);
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
|
@ -352,7 +354,7 @@ void Main::showReboot(void) {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void Main::showFactoryRst(void) {
|
void Main::showFactoryRst(void) {
|
||||||
DPRINTLN(F("Main::showFactoryRst"));
|
DBGMAIN(F("Main::showFactoryRst"));
|
||||||
String content = "";
|
String content = "";
|
||||||
int refresh = 3;
|
int refresh = 3;
|
||||||
if(mWeb->args() > 0) {
|
if(mWeb->args() > 0) {
|
||||||
|
@ -381,7 +383,7 @@ void Main::showFactoryRst(void) {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
time_t Main::getNtpTime(void) {
|
time_t Main::getNtpTime(void) {
|
||||||
//DPRINTLN(F("Main::getNtpTime"));
|
//DBGMAIN(F("Main::getNtpTime"));
|
||||||
time_t date = 0;
|
time_t date = 0;
|
||||||
IPAddress timeServer;
|
IPAddress timeServer;
|
||||||
uint8_t buf[NTP_PACKET_SIZE];
|
uint8_t buf[NTP_PACKET_SIZE];
|
||||||
|
@ -419,7 +421,7 @@ time_t Main::getNtpTime(void) {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void Main::sendNTPpacket(IPAddress& address) {
|
void Main::sendNTPpacket(IPAddress& address) {
|
||||||
//DPRINTLN(F("Main::sendNTPpacket"));
|
//DBGMAIN(F("Main::sendNTPpacket"));
|
||||||
uint8_t buf[NTP_PACKET_SIZE] = {0};
|
uint8_t buf[NTP_PACKET_SIZE] = {0};
|
||||||
|
|
||||||
buf[0] = B11100011; // LI, Version, Mode
|
buf[0] = B11100011; // LI, Version, Mode
|
||||||
|
@ -440,7 +442,7 @@ void Main::sendNTPpacket(IPAddress& address) {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
String Main::getDateTimeStr(time_t t) {
|
String Main::getDateTimeStr(time_t t) {
|
||||||
//DPRINTLN(F("Main::getDateTimeStr"));
|
//DBGMAIN(F("Main::getDateTimeStr"));
|
||||||
char str[20] = {0};
|
char str[20] = {0};
|
||||||
if(0 == t)
|
if(0 == t)
|
||||||
sprintf(str, "n/a");
|
sprintf(str, "n/a");
|
||||||
|
@ -454,7 +456,7 @@ String Main::getDateTimeStr(time_t t) {
|
||||||
// calculates the daylight saving time for middle Europe. Input: Unixtime in UTC
|
// calculates the daylight saving time for middle Europe. Input: Unixtime in UTC
|
||||||
// from: https://forum.arduino.cc/index.php?topic=172044.msg1278536#msg1278536
|
// from: https://forum.arduino.cc/index.php?topic=172044.msg1278536#msg1278536
|
||||||
time_t Main::offsetDayLightSaving (uint32_t local_t) {
|
time_t Main::offsetDayLightSaving (uint32_t local_t) {
|
||||||
//DPRINTLN(F("Main::offsetDayLightSaving"));
|
//DBGMAIN(F("Main::offsetDayLightSaving"));
|
||||||
int m = month (local_t);
|
int m = month (local_t);
|
||||||
if(m < 3 || m > 10) return 0; // no DSL in Jan, Feb, Nov, Dez
|
if(m < 3 || m > 10) return 0; // no DSL in Jan, Feb, Nov, Dez
|
||||||
if(m > 3 && m < 10) return 1; // DSL in Apr, May, Jun, Jul, Aug, Sep
|
if(m > 3 && m < 10) return 1; // DSL in Apr, May, Jun, Jul, Aug, Sep
|
||||||
|
|
|
@ -23,6 +23,11 @@
|
||||||
#include "crc.h"
|
#include "crc.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
|
#ifdef DEBUG_HMMAIN
|
||||||
|
#define DBGMAIN(f,...) do { Serial.printf(PSTR(f), ##__VA_ARGS__); } while (0)
|
||||||
|
#else
|
||||||
|
#define DBGMAIN(x...) do { (void)0; } while (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
const byte mDnsPort = 53;
|
const byte mDnsPort = 53;
|
||||||
|
|
||||||
|
@ -46,7 +51,7 @@ class Main {
|
||||||
virtual void updateCrc(void);
|
virtual void updateCrc(void);
|
||||||
|
|
||||||
inline uint16_t buildEEpCrc(uint32_t start, uint32_t length) {
|
inline uint16_t buildEEpCrc(uint32_t start, uint32_t length) {
|
||||||
DPRINTLN(F("main.h:buildEEpCrc"));
|
DBGMAIN(F("main.h:buildEEpCrc"));
|
||||||
uint8_t buf[32];
|
uint8_t buf[32];
|
||||||
uint16_t crc = 0xffff;
|
uint16_t crc = 0xffff;
|
||||||
uint8_t len;
|
uint8_t len;
|
||||||
|
@ -62,16 +67,16 @@ class Main {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool checkEEpCrc(uint32_t start, uint32_t length, uint32_t crcPos) {
|
bool checkEEpCrc(uint32_t start, uint32_t length, uint32_t crcPos) {
|
||||||
//DPRINTLN(F("main.h:checkEEpCrc"));
|
//DBGMAIN(F("main.h:checkEEpCrc"));
|
||||||
uint16_t crcRd, crcCheck;
|
uint16_t crcRd, crcCheck;
|
||||||
crcCheck = buildEEpCrc(start, length);
|
crcCheck = buildEEpCrc(start, length);
|
||||||
mEep->read(crcPos, &crcRd);
|
mEep->read(crcPos, &crcRd);
|
||||||
//DPRINTLN("CRC RD: " + String(crcRd, HEX) + " CRC CALC: " + String(crcCheck, HEX));
|
//DBGMAIN("CRC RD: " + String(crcRd, HEX) + " CRC CALC: " + String(crcCheck, HEX));
|
||||||
return (crcCheck == crcRd);
|
return (crcCheck == crcRd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void eraseSettings(bool all = false) {
|
void eraseSettings(bool all = false) {
|
||||||
//DPRINTLN(F("main.h:eraseSettings"));
|
//DBGMAIN(F("main.h:eraseSettings"));
|
||||||
uint8_t buf[64] = {0};
|
uint8_t buf[64] = {0};
|
||||||
uint16_t addr = (all) ? ADDR_START : ADDR_START_SETTINGS;
|
uint16_t addr = (all) ? ADDR_START : ADDR_START_SETTINGS;
|
||||||
uint16_t end;
|
uint16_t end;
|
||||||
|
@ -87,7 +92,7 @@ class Main {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool checkTicker(uint32_t *ticker, uint32_t interval) {
|
inline bool checkTicker(uint32_t *ticker, uint32_t interval) {
|
||||||
//DPRINT(F("c"));
|
//DBGMAIN(F("c"));
|
||||||
uint32_t mil = millis();
|
uint32_t mil = millis();
|
||||||
if(mil >= *ticker) {
|
if(mil >= *ticker) {
|
||||||
*ticker = mil + interval;
|
*ticker = mil + interval;
|
||||||
|
@ -102,7 +107,7 @@ class Main {
|
||||||
}
|
}
|
||||||
|
|
||||||
void stats(void) {
|
void stats(void) {
|
||||||
DPRINTLN(F("main.h:stats"));
|
DBGMAIN(F("main.h:stats"));
|
||||||
uint32_t free;
|
uint32_t free;
|
||||||
uint16_t max;
|
uint16_t max;
|
||||||
uint8_t frag;
|
uint8_t frag;
|
||||||
|
|
|
@ -16,7 +16,6 @@ Thanks go to all who contributed, and are continuing to contribute,
|
||||||
by providing their time, equipment, and ingenuity!
|
by providing their time, equipment, and ingenuity!
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Required Hardware Setup
|
Required Hardware Setup
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
|
@ -26,11 +25,61 @@ Required Hardware Setup
|
||||||
- NRF24L01+ Radio Module connected as described, e.g., in [2]
|
- NRF24L01+ Radio Module connected as described, e.g., in [2]
|
||||||
(Instructions at [3] should work identically, but [2] has more
|
(Instructions at [3] should work identically, but [2] has more
|
||||||
pretty pictures.)
|
pretty pictures.)
|
||||||
- TMRh20's 'Optimized High Speed nRF24L01+ Driver' [3], installed
|
- TMRh20's 'Optimized High Speed nRF24L01+ Driver' [3], installed
|
||||||
as per the instructions given in [4]
|
as per the instructions given in [4]
|
||||||
- Python Library Wrapper, as per [5]
|
- Python Library Wrapper, as per [5]
|
||||||
|
|
||||||
|
|
||||||
|
Building the NRF24 Python Wrapper
|
||||||
|
---------------------------------
|
||||||
|
|
||||||
|
You have to install the NRF24 Python Library, as a Dependency for the Raspberry Pi Version of Ahoy.
|
||||||
|
|
||||||
|
To do that correctly, I have contacted the developer of NRF24 via github
|
||||||
|
[Python 3 Wrapper not installing properly #845](https://github.com/nRF24/RF24/issues/845)
|
||||||
|
as I could not get the Python Wrapper for NRF24 to be built.
|
||||||
|
|
||||||
|
- Install Raspberry Pi OS lite x86 with raspberry pi imager
|
||||||
|
- Connect nrf24 module to raspberry pi (as described in github)
|
||||||
|
- Login with user pi
|
||||||
|
- Execute `sudo apt update && sudo apt -y upgrade`
|
||||||
|
- Execute `sudo raspi-config` and
|
||||||
|
- Select "Expand filesystem" in "Advanced Options"
|
||||||
|
- Activate "SPI" in "Interface Options"
|
||||||
|
- "Finish" to exit `raspi-config` Tool, reboot YES!
|
||||||
|
- Login as pi user again
|
||||||
|
|
||||||
|
```code
|
||||||
|
sudo apt install cmake git python3-dev libboost-python-dev python3-pip python3-rpi.gpio
|
||||||
|
|
||||||
|
sudo ln -s $(ls /usr/lib/$(ls /usr/lib/gcc | \
|
||||||
|
tail -1)/libboost_python3*.so | \
|
||||||
|
tail -1) /usr/lib/$(ls /usr/lib/gcc | \
|
||||||
|
tail -1)/libboost_python3.so
|
||||||
|
|
||||||
|
git clone https://github.com/nRF24/RF24.git
|
||||||
|
cd RF24
|
||||||
|
|
||||||
|
export RF24_DRIVER=SPIDEV
|
||||||
|
rm Makefile.inc #just to make sure there is no old stuff
|
||||||
|
mkdir build && cd build
|
||||||
|
cmake ..
|
||||||
|
make
|
||||||
|
sudo make install
|
||||||
|
|
||||||
|
cd ../pyRF24
|
||||||
|
rm -r ./build/ ./dist/ ./RF24.egg-info/ ./__pycache__/ #just to make sure there is no old stuff
|
||||||
|
python3 -m pip install --upgrade pip
|
||||||
|
python3 -m pip install .
|
||||||
|
python3 -m pip list #watch for RF24 module - if its there its installed
|
||||||
|
|
||||||
|
cd ..
|
||||||
|
cd examples_linux/
|
||||||
|
python3 getting_started.py # to test and see whether RF24 class can be loaded as module in python correctly
|
||||||
|
```
|
||||||
|
|
||||||
|
If there are no error messages on the last step, then the NRF24 Wrapper has been installed successfully.
|
||||||
|
|
||||||
|
|
||||||
Example Run
|
Example Run
|
||||||
-----------
|
-----------
|
||||||
|
@ -81,7 +130,7 @@ This can be used to inject debug payloads
|
||||||
The message must be in hexlified format
|
The message must be in hexlified format
|
||||||
|
|
||||||
Use of variables:
|
Use of variables:
|
||||||
* tttttttt expands to current time like we know from our `80 0b` command
|
* `tttttttt` expands to current time like we know from our `80 0b` command
|
||||||
|
|
||||||
Example injects exactly the same as we normally use to poll data
|
Example injects exactly the same as we normally use to poll data
|
||||||
|
|
||||||
|
@ -139,4 +188,3 @@ References
|
||||||
- [3] https://nrf24.github.io/RF24/index.html
|
- [3] https://nrf24.github.io/RF24/index.html
|
||||||
- [4] https://nrf24.github.io/RF24/md_docs_linux_install.html
|
- [4] https://nrf24.github.io/RF24/md_docs_linux_install.html
|
||||||
- [5] https://nrf24.github.io/RF24/md_docs_python_wrapper.html
|
- [5] https://nrf24.github.io/RF24/md_docs_python_wrapper.html
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue