Merge remote-tracking branch 'origin/use-eeprom' into no-more-strings
This commit is contained in:
commit
fb0afa7e43
@ -2,6 +2,7 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <Ethernet.h>
|
#include <Ethernet.h>
|
||||||
|
#include <EEPROM.h>
|
||||||
|
|
||||||
// Additoinal Libraries
|
// Additoinal Libraries
|
||||||
#include <cJSON.h>
|
#include <cJSON.h>
|
||||||
@ -13,6 +14,7 @@
|
|||||||
|
|
||||||
// My Includes
|
// My Includes
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "eeprom_init.h"
|
||||||
#include "button.h"
|
#include "button.h"
|
||||||
#include "slowPWM.h"
|
#include "slowPWM.h"
|
||||||
|
|
||||||
@ -72,6 +74,7 @@ LiquidScreen home_screen(KettleState_line, kettle_power_line);
|
|||||||
LiquidMenu menu(lcd);
|
LiquidMenu menu(lcd);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
StoreEEPROM();
|
||||||
|
|
||||||
unsigned long lastRun = millis() - UpdateInterval;
|
unsigned long lastRun = millis() - UpdateInterval;
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
83
boil_kettle/eeprom_init.h
Normal file
83
boil_kettle/eeprom_init.h
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
#include <EEPROM.h>
|
||||||
|
|
||||||
|
const uint8_t CompileTimeP[] PROGMEM = __DATE__ " " __TIME__;
|
||||||
|
const size_t ConfAddress = sizeof(CompileTimeP);
|
||||||
|
|
||||||
|
unsigned char b, e = -1, *p = (uint8_t*)CompileTimeP - 1;
|
||||||
|
|
||||||
|
struct Vessel {
|
||||||
|
char name[16];
|
||||||
|
char setpoint[20];
|
||||||
|
char sensor[20];
|
||||||
|
double Rref;
|
||||||
|
double RNominal;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Topic {
|
||||||
|
char root[10];
|
||||||
|
Vessel mash;
|
||||||
|
Vessel boil;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Mqtt {
|
||||||
|
IPAddress broker;
|
||||||
|
char user[10];
|
||||||
|
char password[21];
|
||||||
|
Topic topic;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ConfigData {
|
||||||
|
Mqtt mqtt;
|
||||||
|
int interval;
|
||||||
|
int period;
|
||||||
|
uint8_t threshold;
|
||||||
|
uint8_t hysteresis;
|
||||||
|
};
|
||||||
|
|
||||||
|
void StoreEEPROM() {
|
||||||
|
while( b = pgm_read_byte( ++p ) ){
|
||||||
|
if( b != EEPROM[++e] ){
|
||||||
|
|
||||||
|
Vessel BoilKettle;
|
||||||
|
strcpy(BoilKettle.name, "boil_kettle");
|
||||||
|
strcpy(BoilKettle.setpoint, BOIL_SETPOINT_TOPIC);
|
||||||
|
strcpy(BoilKettle.sensor, BOIL_ACTUAL_TOPIC);
|
||||||
|
BoilKettle.Rref = RREF_KETTLE;
|
||||||
|
BoilKettle.RNominal = RNOMINAL_KETTLE;
|
||||||
|
|
||||||
|
// Vessel MashTun {mashname, MASH_SETPOINT_TOPIC, MASH_ACTUAL_TOPIC, RREF_MASH, RNOMINAL_MASH};
|
||||||
|
Vessel MashTun;
|
||||||
|
strcpy(MashTun.name, "mash_tun");
|
||||||
|
strcpy(MashTun.setpoint, MASH_SETPOINT_TOPIC);
|
||||||
|
strcpy(MashTun.sensor, MASH_ACTUAL_TOPIC);
|
||||||
|
MashTun.Rref = RREF_MASH;
|
||||||
|
MashTun.RNominal = RNOMINAL_MASH;
|
||||||
|
|
||||||
|
Topic mqtt_topics;
|
||||||
|
strcpy(mqtt_topics.root,TOPIC_ROOT);
|
||||||
|
mqtt_topics.mash = MashTun;
|
||||||
|
mqtt_topics.boil = BoilKettle;
|
||||||
|
|
||||||
|
Mqtt mqtt_data;
|
||||||
|
mqtt_data.broker = MQTT_BROKER;
|
||||||
|
strcpy(mqtt_data.user, MQTT_USER);
|
||||||
|
strcpy(mqtt_data.password, MQTT_PASSWORD);
|
||||||
|
mqtt_data.topic = mqtt_topics;
|
||||||
|
|
||||||
|
|
||||||
|
ConfigData conf {
|
||||||
|
mqtt_data,
|
||||||
|
UpdateInterval,
|
||||||
|
PeriodPWM,
|
||||||
|
ThreshPWR,
|
||||||
|
Hysteresis
|
||||||
|
};
|
||||||
|
|
||||||
|
EEPROM.put(ConfAddress, conf);
|
||||||
|
Serial.println(conf.mqtt.broker);
|
||||||
|
|
||||||
|
while( b = pgm_read_byte( p++ ) ) EEPROM[e++] = b;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,21 +1,34 @@
|
|||||||
void ConnectMQTT() {
|
void ConnectMQTT() {
|
||||||
static const char *password = MQTT_PASSWORD;
|
ConfigData config;
|
||||||
static const char *user = MQTT_USER;
|
EEPROM.get(ConfAddress, config);
|
||||||
|
|
||||||
|
static const char *user = config.mqtt.user;
|
||||||
|
static const char *password = config.mqtt.password;
|
||||||
|
//config.mqtt.topic.root
|
||||||
|
//config.mqtt.broker
|
||||||
|
|
||||||
while (!mqtt_client.connect("brewhouse", user, password)) {
|
while (!mqtt_client.connect("brewhouse", user, password)) {
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
char topic[30];
|
char topic[30];
|
||||||
strcpy(topic,TOPIC_ROOT);
|
strcpy(topic,config.mqtt.topic.root);
|
||||||
strcat(topic,BOIL_SETPOINT_TOPIC);
|
strcat(topic,config.mqtt.topic.boil.setpoint);
|
||||||
|
mqtt_client.subscribe(topic);
|
||||||
|
|
||||||
|
strcpy(topic,config.mqtt.topic.root);
|
||||||
|
strcat(topic,config.mqtt.topic.mash.setpoint);
|
||||||
mqtt_client.subscribe(topic);
|
mqtt_client.subscribe(topic);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageReceived(char* topic, byte* payload, unsigned int length) {
|
void MessageReceived(char* topic, byte* payload, unsigned int length) {
|
||||||
|
ConfigData config;
|
||||||
|
EEPROM.get(ConfAddress, config);
|
||||||
|
|
||||||
char buf[30];
|
char buf[30];
|
||||||
strcpy(buf,TOPIC_ROOT);
|
strcpy(buf,config.mqtt.topic.root);
|
||||||
strcat(buf,BOIL_SETPOINT_TOPIC);
|
strcat(buf,config.mqtt.topic.boil.setpoint);
|
||||||
|
|
||||||
char msg[length+1];
|
char msg[length+1];
|
||||||
|
|
||||||
@ -37,6 +50,8 @@ void MessageReceived(char* topic, byte* payload, unsigned int length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void SendSensorData() {
|
static void SendSensorData() {
|
||||||
|
ConfigData config;
|
||||||
|
EEPROM.get(ConfAddress, config);
|
||||||
|
|
||||||
char *string = NULL;
|
char *string = NULL;
|
||||||
cJSON *entity = NULL;
|
cJSON *entity = NULL;
|
||||||
@ -44,14 +59,15 @@ static void SendSensorData() {
|
|||||||
cJSON *units = NULL;
|
cJSON *units = NULL;
|
||||||
|
|
||||||
cJSON *monitor = cJSON_CreateObject();
|
cJSON *monitor = cJSON_CreateObject();
|
||||||
cJSON_AddStringToObject(monitor, "entity", "boil_kettle");
|
cJSON_AddStringToObject(monitor, "entity", config.mqtt.topic.boil.name);
|
||||||
cJSON_AddNumberToObject(monitor, "setpoint", KettleDuty);
|
cJSON_AddNumberToObject(monitor, "setpoint", KettleDuty);
|
||||||
cJSON_AddStringToObject(monitor, "units", "%");
|
cJSON_AddStringToObject(monitor, "units", "%");
|
||||||
char *msg = cJSON_Print(monitor);
|
char *msg = cJSON_Print(monitor);
|
||||||
|
|
||||||
char topic[30];
|
char topic[30];
|
||||||
strcpy(topic,TOPIC_ROOT);
|
strcpy(topic,config.mqtt.topic.root);
|
||||||
strcat(topic,BOIL_ACTUAL_TOPIC);
|
strcat(topic,config.mqtt.topic.boil.sensor);
|
||||||
|
|
||||||
|
|
||||||
mqtt_client.publish(topic, msg);
|
mqtt_client.publish(topic, msg);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user