Compare commits
No commits in common. "6930494e0c68fdd75307a9a9597695ad9f756b77" and "8bcb5d847fd0e75c88e784b5233303bfba3a9892" have entirely different histories.
6930494e0c
...
8bcb5d847f
2
.gitignore
vendored
2
.gitignore
vendored
@ -35,3 +35,5 @@
|
||||
# Custom
|
||||
*.bin
|
||||
credentials.h
|
||||
src/app/*
|
||||
!src/app/*.ino
|
@ -22,7 +22,6 @@
|
||||
#define CHAN 108 //0-125
|
||||
#define RECV_CHECK 5000 //We test every 5s if we received something
|
||||
#define WIFI_CHECK_TIMEOUT 20000
|
||||
#define PREVENTIVE_RESET_DELAY 18000000 //Every 5 hours
|
||||
|
||||
uint8_t payload[32] = {0};
|
||||
DataPacket dp;
|
||||
@ -40,13 +39,11 @@ HttpClient DBHost(DB_SERVER, PATH);
|
||||
Dictionary<DictionaryHelper::StringEntity> weatherStationPostData, mailboxPostData;
|
||||
|
||||
const uint8_t ADDR[] = "WEST1", ADDR2[] = "ABCDE";
|
||||
uint32_t timeStamp(0), irqSaver(0), resetTimeStamp(0);
|
||||
uint64_t timeStamp(0), irqSaver(0);
|
||||
uint32_t freeMem(0);
|
||||
uint16_t biggestContigMemBlock(0);
|
||||
uint8_t frag(0);
|
||||
int insertIntoDBError(0);
|
||||
volatile boolean IRQFlag(false);
|
||||
boolean waitingForResetSignal(false), resetNow(false);
|
||||
|
||||
IRAM_ATTR void NRFIRQsHandler(void *p)
|
||||
{
|
||||
@ -161,21 +158,19 @@ void loop()
|
||||
{
|
||||
memcpy(&wsdp, payload, sizeof(wsdp));
|
||||
debugStruct(&wsdp);
|
||||
insertIntoDBError = insertIntoDB(&wsdp);
|
||||
insertIntoDB(&wsdp);
|
||||
}
|
||||
break;
|
||||
case CONNECTED_MAILBOX:
|
||||
{
|
||||
memcpy(&mdp, payload, sizeof(mdp));
|
||||
debugStruct(&mdp);
|
||||
insertIntoDBError = insertIntoDB(&mdp);
|
||||
insertIntoDB(&mdp);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if(waitingForResetSignal)resetNow = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -206,21 +201,19 @@ void loop()
|
||||
{
|
||||
memcpy(&wsdp, payload, sizeof(wsdp));
|
||||
debugStruct(&wsdp);
|
||||
insertIntoDBError = insertIntoDB(&wsdp);
|
||||
insertIntoDB(&wsdp);
|
||||
}
|
||||
break;
|
||||
case CONNECTED_MAILBOX:
|
||||
{
|
||||
memcpy(&mdp, payload, sizeof(mdp));
|
||||
debugStruct(&mdp);
|
||||
insertIntoDBError = insertIntoDB(&mdp);
|
||||
insertIntoDB(&mdp);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if(waitingForResetSignal)resetNow = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -261,19 +254,6 @@ void loop()
|
||||
}
|
||||
timeStamp = millis();
|
||||
}
|
||||
|
||||
//Here we handle the reset
|
||||
if(millis() - resetTimeStamp > PREVENTIVE_RESET_DELAY)
|
||||
{
|
||||
Serial.println("Waiting next payload before resetting MCU :( !");
|
||||
waitingForResetSignal = true;
|
||||
resetTimeStamp = millis();
|
||||
}
|
||||
|
||||
if((waitingForResetSignal && resetNow) || insertIntoDBError == -125)
|
||||
{
|
||||
ESP.reset();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -291,7 +271,7 @@ void lostConnectionFunc(const WiFiEventStationModeDisconnected &event)
|
||||
Serial.println("Lost connection, will try to reconnect ...");
|
||||
}
|
||||
|
||||
int insertIntoDB(WeatherStationDataPacket *p)
|
||||
void insertIntoDB(WeatherStationDataPacket *p)
|
||||
{
|
||||
char buffer[100] = "";
|
||||
int result(0);
|
||||
@ -329,10 +309,27 @@ int insertIntoDB(WeatherStationDataPacket *p)
|
||||
else
|
||||
{
|
||||
Serial.printf("Failed to post data : error(%d)\n", result);
|
||||
if(result == -125)
|
||||
{
|
||||
WiFi.disconnect();
|
||||
WiFi.begin(SSID, PWD);
|
||||
|
||||
while(!WiFi.isConnected())
|
||||
{
|
||||
Serial.println("Reconnecting !");
|
||||
}
|
||||
if((result = DBHost.sendHttpQuery(HttpClient::HttpRequestMethod::POST, NULL, &weatherStationPostData)) == 0)
|
||||
{
|
||||
HttpClient::HTTP_CODE response = DBHost.isReplyAvailable(2000);
|
||||
Serial.printf("Second send got response code : %u\n", response);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.printf("Second send failed to post data : error(%d)\n", result);
|
||||
}
|
||||
}
|
||||
}
|
||||
DBHost.stop();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void debugStruct(WeatherStationDataPacket *p)
|
||||
@ -370,7 +367,7 @@ void debugStruct(WeatherStationDataPacket *p)
|
||||
Serial.println(" *C");
|
||||
}
|
||||
|
||||
int insertIntoDB(MailboxDataPacket *p)
|
||||
void insertIntoDB(MailboxDataPacket *p)
|
||||
{
|
||||
char buffer[100] = "";
|
||||
int result(0);
|
||||
@ -407,8 +404,6 @@ int insertIntoDB(MailboxDataPacket *p)
|
||||
Serial.printf("Failed to post data : error(%d)\n", result);
|
||||
}
|
||||
DBHost.stop();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void debugStruct(MailboxDataPacket *p)
|
||||
|
@ -1,42 +0,0 @@
|
||||
#ifndef DEFINITION_H
|
||||
#define DEFINITION_H
|
||||
|
||||
#include "packet_format.h"
|
||||
|
||||
//Payload structure
|
||||
typedef struct
|
||||
{
|
||||
uint16_t id;
|
||||
HEADER_e header : 6;
|
||||
} __attribute__((__packed__)) DataPacket;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t id;
|
||||
HEADER_e header : 6;
|
||||
unsigned int ldr : 10;
|
||||
float battery;
|
||||
float bmpTemp;
|
||||
float bmpPress;
|
||||
float humidity;
|
||||
float compensatedHumidity;
|
||||
float htuTemp;
|
||||
} __attribute__((__packed__)) WeatherStationDataPacket;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MAILBOX_LETTER = 0,
|
||||
MAILBOX_PACKAGE,
|
||||
MAILBOX_COLLECTED,
|
||||
MAILBOX_UNKNOWN,
|
||||
} MAILBOX_EVENT_e;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t id;
|
||||
HEADER_e header : 6;
|
||||
float battery;
|
||||
MAILBOX_EVENT_e mailbox_event;
|
||||
} __attribute__((__packed__)) MailboxDataPacket;
|
||||
|
||||
#endif //DEFINITION_H
|
@ -1,6 +0,0 @@
|
||||
#ifndef PACKET_FORMAT_H
|
||||
#define PACKET_FORMAT_H
|
||||
|
||||
enum HEADER_e {WEATHER_STATION = 0, CONNECTED_MAILBOX};
|
||||
|
||||
#endif //PACKET_FORMAT_H
|
Loading…
Reference in New Issue
Block a user