Skip to content

Commit

Permalink
Detection of DS18b20 pin
Browse files Browse the repository at this point in the history
  • Loading branch information
universam1 committed Aug 22, 2018
1 parent e447e27 commit 92a9f77
Show file tree
Hide file tree
Showing 4 changed files with 329 additions and 212 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ Check out [IOT DEVICE PULLS ITS WEIGHT IN HOME BREWING](http://hackaday.com/2017

***

## Firmware download:
***https://github.com/universam1/iSpindel/releases***
## [Firmware download here](https://github.com/universam1/iSpindel/releases)

***

## ChangeLog

| Date | Note |
| :--------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 16.08.2018 | Firmware 5.9.1: Fixing Ubidots issue and extending MQTT |
| 09.08.2018 | Firmware 5.9.0: Support for MQTT, InfluxDB (Thanks to jmelhus, iceaway and thorrak) |
| 13.05.2018 | Firmware 5.8.6: allow longer fields for polynominal, SSID and Password |
| 15.03.2018 | Firmware 5.8.5: adding support for Prometheus Pushgateway, thanks to @jankeesv |
| 22.08.2018 | **Firmware 6.0.0**:<br>1. Alternative pin for OneWire tempearuture sensor DS18B20 now possible. This allows a different PCB schema to use either pin `D1` or `D6`. <br>2. Auto detection of OneWire pin, successfull detected pin will be saved together with a config `save` action. Output of detailed debug information of OneWire Sensor during searches, helping those with hardware issues. <br>3. Increased battery lifetime of about 20% by reducing the runtime to ~2200ms through various tunings.<br>4. Using *Interrupts* instead of delays to read the Accelerometer, allows significant shorter read intervals <br>5. Shorter read cycles allow *more precision*, increased samples from 7 to 39 samples that still fit into the necessary wait state for the Temp sensor! |
| 16.08.2018 | Firmware 5.9.1: Fixing Ubidots issue and extending MQTT |
| 09.08.2018 | Firmware 5.9.0: Support for MQTT, InfluxDB (Thanks to jmelhus, iceaway and thorrak) |
| 13.05.2018 | Firmware 5.8.6: allow longer fields for polynominal, SSID and Password |
| 15.03.2018 | Firmware 5.8.5: adding support for Prometheus Pushgateway, thanks to @jankeesv |
| 08.03.2018 | Firmware 5.8.4: adding support for logging temperature data in Fahrenheit and Kelvin, thanks to @iceaway |
| 05.03.2018 | Firmware 5.8.3: Support for InfluxDB as additional backend, thanks to @iceaway |
| 23.02.2018 | New drawer version 'mwx-Edition' using threaded bolt nut and washer - thanks to @mwx |
Expand Down
18 changes: 9 additions & 9 deletions pio/lib/Globals/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
extern Ticker flasher;

// defines go here
#define FIRMWAREVERSION "5.9.1"
#define FIRMWAREVERSION "6.0.0"

#define API_FHEM true
#define API_UBIDOTS true
Expand All @@ -42,29 +42,29 @@ extern Ticker flasher;
#define CONSOLELN CONSOLE
#define CONSOLEF CONSOLE
#else
#define CONSOLE(x) \
#define CONSOLE(...) \
do \
{ \
Serial.print(x); \
Serial.print(__VA_ARGS__); \
} while (0)
#define CONSOLELN(x) \
#define CONSOLELN(...) \
do \
{ \
Serial.println(x); \
Serial.println(__VA_ARGS__); \
} while (0)
#endif

#define PORTALTIMEOUT 300

#define ADCDIVISOR 191.8
#define ONE_WIRE_BUS D6 // DS18B20 on ESP pin12
#define OW_PINS (const uint8_t[]){D1, D6}
#define RESOLUTION 12 // 12bit resolution == 750ms update rate
#define OWinterval (800 / (1 << (12 - RESOLUTION)))
#define OWinterval (760 / (1 << (12 - RESOLUTION)))
#define CFGFILE "/config.json"
#define TKIDSIZE 40
#define MEDIANROUNDS 7
#define ACCINTERVAL 200
#define MEDIANAVRG 3
#define MEDIANROUNDS 39
#define MEDIANAVRG 29

#define CBP_ENDPOINT "/api/hydrometer/v1/data"

Expand Down
98 changes: 52 additions & 46 deletions pio/lib/Sender/Sender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,45 +33,51 @@ void SenderClass::add(String id, int32_t value)
_jsonVariant[id] = value;
}

bool SenderClass::sendMQTT(String server, uint16_t port, String username, String password, String name) {
_mqttClient.setClient(_client);
_mqttClient.setServer(server.c_str(), port);
_mqttClient.setCallback([this](char* topic, byte* payload, unsigned int length) { this->mqttCallback(topic, payload, length); });

while (!_mqttClient.connected()) {
CONSOLELN(F("Attempting MQTT connection"));
// Attempt to connect
if (_mqttClient.connect(name.c_str(), username.c_str(), password.c_str())) {
CONSOLELN(F("Connected to MQTT"));
}
else {
CONSOLELN(F("Failed MQTT connection, return code:"));
CONSOLELN(_mqttClient.state());
CONSOLELN(F("Retrying MQTT connection in 5 seconds"));
// Wait 5 seconds before retrying
delay(5000);
}
}
//MQTT publish values
for (const auto &kv : _jsonVariant.as<JsonObject>())
{
CONSOLELN("MQTT publish: ispindel/" + name + "/" + kv.key + "/" + kv.value.as<String>());
_mqttClient.publish(("ispindel/" + name + "/" + kv.key).c_str(), kv.value.as<String>().c_str());
_mqttClient.loop(); //This should be called regularly to allow the client to process incoming messages and maintain its connection to the server.
}

CONSOLELN(F("Closing MQTT connection"));
_mqttClient.disconnect();
delay(100); // allow gracefull session close
return true;
bool SenderClass::sendMQTT(String server, uint16_t port, String username, String password, String name)
{
_mqttClient.setClient(_client);
_mqttClient.setServer(server.c_str(), port);
_mqttClient.setCallback([this](char *topic, byte *payload, unsigned int length) { this->mqttCallback(topic, payload, length); });

while (!_mqttClient.connected())
{
CONSOLELN(F("Attempting MQTT connection"));
// Attempt to connect
if (_mqttClient.connect(name.c_str(), username.c_str(), password.c_str()))
{
CONSOLELN(F("Connected to MQTT"));
}
else
{
CONSOLELN(F("Failed MQTT connection, return code:"));
CONSOLELN(_mqttClient.state());
CONSOLELN(F("Retrying MQTT connection in 5 seconds"));
// Wait 5 seconds before retrying
delay(5000);
}
}
//MQTT publish values
for (const auto &kv : _jsonVariant.as<JsonObject>())
{
CONSOLELN("MQTT publish: ispindel/" + name + "/" + kv.key + "/" + kv.value.as<String>());
_mqttClient.publish(("ispindel/" + name + "/" + kv.key).c_str(), kv.value.as<String>().c_str());
_mqttClient.loop(); //This should be called regularly to allow the client to process incoming messages and maintain its connection to the server.
}

CONSOLELN(F("Closing MQTT connection"));
_mqttClient.disconnect();
delay(100); // allow gracefull session close
return true;
}
void SenderClass::mqttCallback(char* topic, byte* payload, unsigned int length) {
CONSOLELN(F("MQTT message arrived ["));
CONSOLELN(topic);
CONSOLELN(F("] "));
for (unsigned int i = 0; i < length; i++) {
CONSOLE((char)payload[i]);
}
void SenderClass::mqttCallback(char *topic, byte *payload, unsigned int length)
{
CONSOLELN(F("MQTT message arrived ["));
CONSOLELN(topic);
CONSOLELN(F("] "));
for (unsigned int i = 0; i < length; i++)
{
CONSOLE((char)payload[i]);
}
}

bool SenderClass::sendTCP(String server, uint16_t port)
Expand All @@ -80,7 +86,7 @@ bool SenderClass::sendTCP(String server, uint16_t port)

if (_client.connect(server.c_str(), port))
{
CONSOLELN(F("Sender: TCP stream"));
CONSOLELN(F("\nSender: TCP stream"));
_jsonVariant.printTo(_client);
_client.println();
}
Expand Down Expand Up @@ -139,6 +145,7 @@ bool SenderClass::sendGenericPost(String server, String url, uint16_t port)
}

http.end();
delay(100); // allow gracefull session close
return true;
}

Expand All @@ -155,7 +162,7 @@ bool SenderClass::sendInfluxDB(String server, uint16_t port, String db, String n

if (username.length() > 0)
{
http.setAuthorization(username.c_str(), password.c_str());
http.setAuthorization(username.c_str(), password.c_str());
}

http.addHeader("User-Agent", "iSpindel");
Expand Down Expand Up @@ -196,14 +203,14 @@ bool SenderClass::sendInfluxDB(String server, uint16_t port, String db, String n
}

http.end();

delay(100); // allow gracefull session close
return true;
}

bool SenderClass::sendPrometheus(String server, uint16_t port, String job, String instance)
{
HTTPClient http;

// the path looks like /metrics/job/<JOBNAME>[/instance/<INSTANCENAME>]
String uri = "/metrics/job/";
uri += job;
Expand Down Expand Up @@ -254,6 +261,7 @@ bool SenderClass::sendPrometheus(String server, uint16_t port, String job, Strin
}

http.end();
delay(100); // allow gracefull session close
return true;
}

Expand All @@ -263,7 +271,7 @@ bool SenderClass::sendUbidots(String token, String name)

if (_client.connect(UBISERVER, 80))
{
CONSOLELN(F("Sender: Ubidots posting"));
CONSOLELN(F("\nSender: Ubidots posting"));

String msg = F("POST /api/v1.6/devices/");
msg += name;
Expand All @@ -274,8 +282,6 @@ bool SenderClass::sendUbidots(String token, String name)
msg += "\r\n";

_client.println(msg);
CONSOLELN(msg);

_jsonVariant.printTo(_client);
_client.println();
CONSOLELN(msg);
Expand Down Expand Up @@ -359,7 +365,7 @@ bool SenderClass::sendTCONTROL(String server, uint16_t port)
if (_client.connect(server.c_str(), port))
{

CONSOLELN(F("Sender: TCONTROL"));
CONSOLELN(F("\nSender: TCONTROL"));
String msg;

for (const auto &kv : _jsonVariant.as<JsonObject>())
Expand Down
Loading

0 comments on commit 92a9f77

Please sign in to comment.