-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from GJKrupa/mqtt-versions
MQTT version with additional syslog logging
- Loading branch information
Showing
25 changed files
with
702 additions
and
358 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.pio | ||
.pioenvs | ||
.piolibdeps | ||
.vscode/ | ||
.vscode/ | ||
secret_config.ini |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[env:lolin_d32] | ||
src_build_flags= | ||
'-D WIFI_SSID="my-ssid"' | ||
'-D WIFI_PASSPHRASE="my-passphrase"' | ||
'-D MQTT_SERVER="server.domain"' | ||
'-D MQTT_PORT=1883' | ||
'-D SYSLOG_ENABLED=1' | ||
'-D SYSLOG_HOST="loghost"' | ||
'-D SYSLOG_PORT=514' | ||
'-D ROOM="garden"' | ||
'-D ALTITUDE=80' | ||
'-D RAIN_MONITOR=0' | ||
'-D BATTERY_MONITOR=0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include "battery_sensor.h" | ||
#include "logging.h" | ||
|
||
#define MAX_VOLTAGE 4.4 * 5.0 | ||
|
||
BatteryHomeSensor::BatteryHomeSensor(int data_pin, int pwr_pin) : | ||
data_pin(data_pin), | ||
pwr_pin(pwr_pin), | ||
data_sent(false), | ||
is_on(false) | ||
{ | ||
if (pwr_pin > 0) | ||
{ | ||
pinMode(pwr_pin, OUTPUT); | ||
} | ||
pinMode(data_pin, INPUT); | ||
} | ||
|
||
String BatteryHomeSensor::name() | ||
{ | ||
return "Battery"; | ||
} | ||
|
||
void BatteryHomeSensor::setup() | ||
{ | ||
} | ||
|
||
void BatteryHomeSensor::submitReading(ReadingSubmitter &submitter) | ||
{ | ||
logln("Getting Battery sensors"); | ||
|
||
uint16_t analogueReading = analogRead(data_pin); | ||
double actual = ((double)analogueReading / 4095.0) * MAX_VOLTAGE; | ||
|
||
submitter.sendReading("battery", actual); | ||
data_sent = true; | ||
} | ||
|
||
bool BatteryHomeSensor::ready() | ||
{ | ||
return true; | ||
} | ||
|
||
bool BatteryHomeSensor::failed() | ||
{ | ||
return false; | ||
} | ||
|
||
bool BatteryHomeSensor::sent() | ||
{ | ||
return data_sent; | ||
} | ||
|
||
bool BatteryHomeSensor::isOn() | ||
{ | ||
return is_on; | ||
} | ||
|
||
void BatteryHomeSensor::switchOn() | ||
{ | ||
if (pwr_pin > 0) | ||
{ | ||
digitalWrite(pwr_pin, HIGH); | ||
} | ||
is_on = true; | ||
} | ||
|
||
void BatteryHomeSensor::switchOff() | ||
{ | ||
if (pwr_pin > 0) | ||
{ | ||
digitalWrite(pwr_pin, LOW); | ||
} | ||
is_on = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
#include <Wire.h> | ||
#include "home_sensor.h" | ||
|
||
class BatteryHomeSensor: public HomeSensor { | ||
public: | ||
BatteryHomeSensor(int data_pin, int pwr_pin); | ||
virtual void submitReading(ReadingSubmitter &submitter); | ||
virtual void setup(); | ||
virtual bool ready(); | ||
virtual bool failed(); | ||
virtual void switchOn(); | ||
virtual void switchOff(); | ||
virtual bool isOn(); | ||
virtual bool sent(); | ||
virtual String name(); | ||
private: | ||
int data_pin; | ||
int pwr_pin; | ||
bool data_sent; | ||
bool is_on; | ||
}; |
Oops, something went wrong.