Voltage measuring included
This commit is contained in:
parent
79344f971e
commit
3c23bfa0c9
|
@ -12,13 +12,14 @@
|
||||||
#include <OneWire.h>
|
#include <OneWire.h>
|
||||||
#include <DallasTemperature.h>
|
#include <DallasTemperature.h>
|
||||||
|
|
||||||
const char* ssid = "ENTER_YOUR_SSID_HERE";
|
const char* ssid = "CTDO-IoT";
|
||||||
const char* password = "ENTER_YOUR_WLAN_PASS_HERE";
|
const char* password = "12345678";
|
||||||
|
|
||||||
#define DEVICENAME "maintopic/devicename"
|
#define DEVICENAME "haus/bad"
|
||||||
#define TOPIC DEVICENAME"/temperature"
|
#define TOPIC DEVICENAME"/temperature"
|
||||||
|
#define TOPICVOLTAGE DEVICENAME"/voltage"
|
||||||
#define ONLINETOPIC DEVICENAME"/online"
|
#define ONLINETOPIC DEVICENAME"/online"
|
||||||
#define MQTTSERVER IPAddress(37, 187, 106, 16) // test.mosquitto.org = 37.187.106.16
|
#define MQTTSERVER IPAddress(195, 160, 169, 11) // test.mosquitto.org = 37.187.106.16
|
||||||
const int sleepTimeS = 300; // Reduce this value for debugging. Increase if you want more battery life
|
const int sleepTimeS = 300; // Reduce this value for debugging. Increase if you want more battery life
|
||||||
|
|
||||||
#define VCCPIN D7
|
#define VCCPIN D7
|
||||||
|
@ -36,6 +37,10 @@ float tempC;
|
||||||
AsyncMqttClient mqttClient;
|
AsyncMqttClient mqttClient;
|
||||||
uint16_t packetId1Pub;
|
uint16_t packetId1Pub;
|
||||||
bool packet1Ack = false;
|
bool packet1Ack = false;
|
||||||
|
uint16_t packetId2Pub;
|
||||||
|
bool packet2Ack = false;
|
||||||
|
float voltage = 0.0;
|
||||||
|
int raw = 0;
|
||||||
|
|
||||||
bool ready = false;
|
bool ready = false;
|
||||||
|
|
||||||
|
@ -52,16 +57,16 @@ char *ftoa( double f, char *a, int precision)
|
||||||
itoa(desimal, a, 10);
|
itoa(desimal, a, 10);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void onMqttPublish(uint16_t packetId) {
|
void onMqttPublish(uint16_t packetId) {
|
||||||
Serial.println("** Publish acknowledged **");
|
// TODO: Only when both packages were acknowledged...
|
||||||
Serial.print(" packetId: ");
|
|
||||||
Serial.println(packetId);
|
|
||||||
// TODO: Only when both packages were acknowledged...
|
|
||||||
if (packetId == packetId1Pub) {
|
if (packetId == packetId1Pub) {
|
||||||
packet1Ack = true;
|
packet1Ack = true;
|
||||||
}
|
}
|
||||||
if (packet1Ack) {
|
if (packetId == packetId2Pub) {
|
||||||
|
packet2Ack = true;
|
||||||
|
}
|
||||||
|
if (packet1Ack && packet2Ack) {
|
||||||
ready = true;
|
ready = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,9 +74,9 @@ void onMqttPublish(uint16_t packetId) {
|
||||||
void onMqttConnect(bool sessionPresent) {
|
void onMqttConnect(bool sessionPresent) {
|
||||||
char buf[7];
|
char buf[7];
|
||||||
packetId1Pub = mqttClient.publish(TOPIC, 1, true, ftoa(tempC, buf, 2));
|
packetId1Pub = mqttClient.publish(TOPIC, 1, true, ftoa(tempC, buf, 2));
|
||||||
|
packetId2Pub = mqttClient.publish(TOPICVOLTAGE, 1, true, ftoa(voltage, buf, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
pinMode(GNDPIN, OUTPUT);
|
pinMode(GNDPIN, OUTPUT);
|
||||||
pinMode(VCCPIN, OUTPUT);
|
pinMode(VCCPIN, OUTPUT);
|
||||||
|
@ -92,6 +97,9 @@ void loop() {
|
||||||
// 0 refers to the first IC on the wire
|
// 0 refers to the first IC on the wire
|
||||||
Serial.println("Requesting Temperature from Device 0");
|
Serial.println("Requesting Temperature from Device 0");
|
||||||
tempC = sensors.getTempCByIndex(0);
|
tempC = sensors.getTempCByIndex(0);
|
||||||
|
raw = analogRead(A0); // 2.428V = 739
|
||||||
|
// Je Tick = 0,003285521V
|
||||||
|
voltage = raw * 0.003285521;
|
||||||
|
|
||||||
Serial.println("Connecting to WIFI");
|
Serial.println("Connecting to WIFI");
|
||||||
// Connect to WiFi
|
// Connect to WiFi
|
||||||
|
|
Loading…
Reference in New Issue