Tidy up DS18B20 reporting. Tidied WiFiManager handling, new Bluetooth app

This commit is contained in:
rljonesau 2019-01-14 14:30:41 +11:00
parent 320b7e8b6f
commit 551205d6bd
6 changed files with 146 additions and 181 deletions

Binary file not shown.

View file

@ -233,23 +233,24 @@ void parentKeyHandler(uint8_t event)
ScreenManager.keyHandler(event); // call into the Screen Manager
}
// Added additional t
int numberOfDevices; // Number of temperature devices found
DeviceAddress tempDeviceAddress;
void printAddress(DeviceAddress deviceAddress)
const char* print18B20Address(DeviceAddress deviceAddress)
{
static char addrStr[32];
addrStr[0] = 0;
for (uint8_t i = 0; i < 8; i++)
{
if (deviceAddress[i] < 16) DebugPort.print("0");
DebugPort.print(deviceAddress[i], HEX);
char subset[8];
sprintf(subset, "%02X%c", deviceAddress[i], i<7 ? ':' : ' ');
strcat(addrStr, subset);
}
return addrStr;
}
void setup() {
char msg[128];
TempSensor.begin();
DebugPort.print("Temperature for the device 1 (index 0) is: ");
DebugPort.println(TempSensor.getTempCByIndex(0));
// initialise TelnetSpy (port 23) as well as Serial to 115200
// Serial is the usual USB connection to a PC
// DO THIS BEFORE WE TRY AND SEND DEBUG INFO!
@ -259,8 +260,47 @@ void setup() {
"*************************************************\r\n");
DebugPort.setBufferSize(8192);
DebugPort.begin(115200);
DebugPort.println("_______________________________________________________________");
DebugPort.println("DS18B20 status dump");
sprintf(msg, " Temperature for device#1 (idx 0) is: %.1f", TempSensor.getTempCByIndex(0));
DebugPort.println(msg);
// locate devices on the bus
DebugPort.print(" Locating DS18B20 devices...");
// initialise DS18B20 temperature sensor(s)
// Grab a count of devices on the wire
int numberOfDevices = TempSensor.getDeviceCount();
sprintf(msg, " Found %d devices", numberOfDevices);
DebugPort.println(msg);
// report parasite power requirements
sprintf(msg, " Parasite power is: %s", TempSensor.isParasitePowerMode() ? "ON" : "OFF");
DebugPort.println(msg);
// Loop through each device, print out address
for(int i=0;i<numberOfDevices; i++)
{
// Search the wire for address
DeviceAddress tempDeviceAddress;
if(TempSensor.getAddress(tempDeviceAddress, i)) {
sprintf(msg, " Found DS18B20 device#%d with address: %s", i+1, print18B20Address(tempDeviceAddress));
DebugPort.println(msg);
sprintf(msg, " Resolution: %d bits", TempSensor.getResolution(tempDeviceAddress));
DebugPort.println(msg);
} else {
sprintf(msg, " Found ghost @ device#%d, but could not detect address. Check power and cabling", i+1);
DebugPort.println(msg);
}
}
TempSensor.setWaitForConversion(false);
TempSensor.requestTemperatures();
lastTemperatureTime = millis();
lastAnimationTime = millis();
NVstore.init();
NVstore.load();
@ -270,64 +310,16 @@ void setup() {
// Initialize the rtc object
Clock.begin();
// initialise DS18B20 temperature sensor(s)
// Grab a count of devices on the wire
numberOfDevices = TempSensor.getDeviceCount();
// locate devices on the bus
DebugPort.print("Locating devices...");
DebugPort.print("Found ");
DebugPort.print(numberOfDevices, DEC);
DebugPort.println(" devices.");
// report parasite power requirements
DebugPort.print("Parasite power is: ");
if (TempSensor.isParasitePowerMode()) Serial.println("ON");
else DebugPort.println("OFF");
// Loop through each device, print out address
for(int i=0;i<numberOfDevices; i++)
{
// Search the wire for address
if(TempSensor.getAddress(tempDeviceAddress, i)) {
DebugPort.print("Found device ");
DebugPort.print(i, DEC);
DebugPort.print(" with address: ");
printAddress(tempDeviceAddress);
DebugPort.println();
DebugPort.print("Resolution actually set to: ");
DebugPort.print(TempSensor.getResolution(tempDeviceAddress), DEC);
DebugPort.println();
} else {
DebugPort.print("Found ghost device at ");
DebugPort.print(i, DEC);
DebugPort.print(" but could not detect address. Check power and cabling");
}
}
TempSensor.setWaitForConversion(false);
TempSensor.requestTemperatures();
lastTemperatureTime = millis();
lastAnimationTime = millis();
ScreenManager.begin();
#if USE_WIFI == 1
bool wifiConnected = initWifi(WiFi_TriggerPin, FAILEDSSID, FAILEDPASSWORD);
initWifi(WiFi_TriggerPin, FAILEDSSID, FAILEDPASSWORD);
#if USE_OTA == 1
initOTA();
#endif // USE_OTA
#if USE_WEBSERVER == 1
// if(wifiConnected) {
DebugPort.println("Starting heater web server");
initWebServer();
/* }
else {
DebugPort.println("SKIPPED starting heater web server");
}*/
initWebServer();
#endif // USE_WEBSERVER
#endif // USE_WIFI

View file

@ -127,9 +127,11 @@ CBluetoothHC05::begin()
// leave HC-05 command mode, return to data mode
digitalWrite(_keyPin, LOW);
}
delay(50);
flush(); // ensure any AT command reponse dribbles are cleaned up!
DebugPort.println("");
}

View file

@ -95,50 +95,52 @@ const uint8_t miniFontBitmaps[] PROGMEM =
0x88, // # #
0x88, // # #
// @39 'H' (3 pixels wide)
// @39 'F' (3 pixels wise)
0xf8, // #####
0xa0, // # #
0x80, // #
// @42 'G' (3 pixels wise)
0xf8, // #####
0x88, // # #
0x98, // # ##
// @45 'H' (3 pixels wide)
0xf8, // #####
0x20, // #
0xf8, // #####
// @42 'P' (3 pixels wide)
0xf8, // #####
0xa0, // # #
0xe0, // ###
// @45 'V' (3 pixels wide)
0xf0, // ####
0x08, // #
0xf0, // ####
// @48 'W' (3 pixels wide)
0xf8, // #####
0x10, // #
0xf8, // #####
// @51 'z' (3 pixels wide)
0x28, // # #
0x38, // ###
0x28, // # #
// @54 'L' (3 pixels wise)
// @48'L' (3 pixels wise)
0xf8, // #####
0x08, // #
0x08, // #
// @57 'T' (3 pixels wise)
// @51 'P' (3 pixels wide)
0xf8, // #####
0xa0, // # #
0xe0, // ###
// @54 'T' (3 pixels wise)
0x80, // #
0xf8, // #####
0x80, // #
// @60 'F' (3 pixels wise)
0xf8, // #####
0xa0, // # #
0x80, // #
// @57 'V' (3 pixels wide)
0xf0, // ####
0x08, // #
0xf0, // ####
// @63 'T' (3 pixels wise)
// @60 'W' (3 pixels wide)
0xf8, // #####
0x88, // # #
0x98, // # ##
0x10, // #
0xf8, // #####
// @63 'z' (3 pixels wide)
0x28, // # #
0x38, // ###
0x28, // # #
};
// Character descriptors for a 3x5 font
@ -169,24 +171,24 @@ const FONT_CHAR_INFO miniFontDescriptors[] PROGMEM =
{3, 5, 36}, // 'C'
{0, 0, 0}, // 'D'
{0, 0, 0}, // 'E'
{3, 5, 60}, // 'F'
{3, 5, 63}, // 'G'
{3, 5, 39}, // 'H'
{3, 5, 39}, // 'F'
{3, 5, 42}, // 'G'
{3, 5, 45}, // 'H'
{0, 0, 0}, // 'I'
{0, 0, 0}, // 'J'
{0, 0, 0}, // 'K'
{3, 5, 54}, // 'L'
{3, 5, 48}, // 'L'
{0, 0, 0}, // 'M'
{0, 0, 0}, // 'N'
{0, 0, 0}, // 'O'
{3, 5, 42}, // 'P'
{3, 5, 51}, // 'P'
{0, 0, 0}, // 'Q'
{0, 0, 0}, // 'R'
{0, 0, 0}, // 'S'
{3, 5, 57}, // 'T'
{3, 5, 54}, // 'T'
{0, 0, 0}, // 'U'
{3, 5, 45}, // 'V'
{3, 5, 48}, // 'W'
{3, 5, 57}, // 'V'
{3, 5, 60}, // 'W'
{0, 0, 0}, // 'X'
{0, 0, 0}, // 'Y'
{0, 0, 0}, // 'Z'
@ -221,7 +223,7 @@ const FONT_CHAR_INFO miniFontDescriptors[] PROGMEM =
{0, 0, 0}, // 'w'
{0, 0, 0}, // 'x'
{0, 0, 0}, // 'y'
{3, 5, 51}, // 'z'
{3, 5, 63}, // 'z'
};
// Font information for Mini Font, a 3x5 font

View file

@ -40,6 +40,11 @@ void interpretJsonCommand(char* pLine)
return;
DebugPort.print("JSON parse... "); DebugPort.print(pLine);
/* for(int i=0; i<strlen(pLine); i++) {
char msg[8];
sprintf(msg, "%02X ", pLine[i]);
DebugPort.print(msg);
}*/
StaticJsonBuffer<512> jsonBuffer; // create a JSON buffer on the heap
JsonObject& obj = jsonBuffer.parseObject(pLine);
@ -138,7 +143,7 @@ void interpretJsonCommand(char* pLine)
bool makeJsonString(CModerator& moderator, char* opStr, int len)
{
StaticJsonBuffer<600> jsonBuffer; // create a JSON buffer on the stack
StaticJsonBuffer<800> jsonBuffer; // create a JSON buffer on the stack
JsonObject& root = jsonBuffer.createObject(); // create object to add JSON commands to
bool bSend = false; // reset should send flag
@ -190,7 +195,7 @@ bool makeJsonString(CModerator& moderator, char* opStr, int len)
void updateJSONclients(bool report)
{
char jsonStr[600];
char jsonStr[800];
if(makeJsonString(JSONmoderator, jsonStr, sizeof(jsonStr))) {
if (report) {

View file

@ -64,7 +64,7 @@ bool initWifi(int initpin,const char *failedssid, const char *failedpassword)
sprintf(msg, "STA MAC address: %02X:%02X:%02X:%02X:%02X:%02X", MAC[0], MAC[1], MAC[2], MAC[3], MAC[4], MAC[5]);
DebugPort.println(msg);
esp_read_mac(MAC, ESP_MAC_WIFI_SOFTAP);
sprintf(msg, "AP MAC address: %02X:%02X:%02X:%02X:%02X:%02X", MAC[0], MAC[1], MAC[2], MAC[3], MAC[4], MAC[5]);
sprintf(msg, " AP MAC address: %02X:%02X:%02X:%02X:%02X:%02X", MAC[0], MAC[1], MAC[2], MAC[3], MAC[4], MAC[5]);
DebugPort.println(msg);
//reset settings - wipe credentials for testing
@ -122,97 +122,61 @@ bool initWifi(int initpin,const char *failedssid, const char *failedpassword)
return true;
}
void doWiFiManager(){
wm.process();
void doWiFiManager()
{
wm.process();
if(startServer) {
long tDelta = millis() - startServer;
if(tDelta > 10000) {
startServer = 0;
initWebServer();
ESP.restart();
}
}
static bool pinDown = false;
static long pinTime = 0;
if(digitalRead(TRIG_PIN) == LOW) {
if(!pinDown)
pinTime = millis();
pinDown = true;
}
else {
if(pinDown) {
pinDown = false;
unsigned long tDelta = millis() - pinTime;
DebugPort.print("Wifi config button tDelta = "); DebugPort.println(tDelta);
if(tDelta > 5000) { // > 5 second press
prepBootIntoConfigPortal(true); // very long press - clear credentials, boot into portal
wm.resetSettings();
DebugPort.println("*** Clearing credentials and rebooting into portal ***");
delay(1000);
ESP.restart();
}
else if(tDelta > 1000) { // > 1 second press
prepBootIntoConfigPortal(false); // long press - boot into SoftAP
DebugPort.println("*** Rebooting into web server ***");
delay(1000);
ESP.restart();
}
else if(tDelta > 50) {
prepBootIntoConfigPortal(true); // short press - boot into Portal
DebugPort.println("*** Rebooting into config portal ***");
delay(1000);
ESP.restart();
}
// contact bounce otherwise!
}
}
// is auto timeout portal running
/* if(portalRunning){
wm.process();
long tDelta = millis() - startTime;
if(tDelta > (timeout*1000)){
DebugPort.println("portaltimeout");
portalRunning = false;
if(startCP){
wm.stopConfigPortal();
}
else{
wm.stopWebPortal();
}
wm.disconnect();
WiFi.softAP("BTCDieselHeater");
WiFi.softAPConfig(IPAddress(192, 168, 100, 1), IPAddress(192, 168, 100, 1), IPAddress(255,255,255,0));
if(startServer) {
long tDelta = millis() - startServer;
if(tDelta > 10000) {
startServer = 0;
initWebServer();
ESP.restart();
}
}
// is configuration portal requested?
// if(TRIG_PIN == 1 && (!portalRunning)) {
if(digitalRead(TRIG_PIN) == LOW && !portalRunning) {
// stopWebServer();
if(startCP){
DebugPort.println("Button Pressed, Starting Config Portal with new AP");
// wm.setConfigPortalBlocking(false);
wm.startConfigPortal();
// TRIG_PIN = 0; // reset the flag
}
else{
DebugPort.println("Button Pressed, Starting Web Portal");
wm.startWebPortal();
// TRIG_PIN = 0; // reset the flag
}
portalRunning = true;
startTime = millis();
}*/
static bool pinDown = false;
static long pinTime = 0;
if(digitalRead(TRIG_PIN) == LOW) {
if(!pinDown)
pinTime = millis();
pinDown = true;
}
else {
if(pinDown) {
pinDown = false;
unsigned long tDelta = millis() - pinTime;
DebugPort.print("Wifi config button tDelta = "); DebugPort.println(tDelta);
if(tDelta > 5000) { // > 5 second press
prepBootIntoConfigPortal(true); // very long press - clear credentials, boot into portal
wm.resetSettings();
DebugPort.println("*** Clearing credentials and rebooting into portal ***");
delay(1000);
ESP.restart();
}
else if(tDelta > 1000) { // > 1 second press
prepBootIntoConfigPortal(false); // long press - boot into SoftAP
DebugPort.println("*** Rebooting into web server ***");
delay(1000);
ESP.restart();
}
else if(tDelta > 50) {
prepBootIntoConfigPortal(true); // short press - boot into Portal
DebugPort.println("*** Rebooting into config portal ***");
delay(1000);
ESP.restart();
}
// contact bounce otherwise!
}
}
}
void saveParamsCallback()
{
startServer = millis();
prepBootIntoConfigPortal(false); // ensure we fall back to SoftAP with our web page in future
isPortalAP = false;
isAP = false;
}
void APstartedCallback(WiFiManager*)