Changed DS18B20 read to a use device address - faster

Seeing 10 second WiFi timeout if BT & WiFI client active, reversed order so Websocket now sends before BT
  - very much more stable now
  - smacks of a UART ISR causing issues with socket kernel code...
This commit is contained in:
Ray Jones 2019-05-09 06:30:26 +10:00
parent e900cb84a7
commit b47a4606dd
3 changed files with 25 additions and 7 deletions

View file

@ -116,8 +116,8 @@
#define RX_DATA_TIMOUT 50
const int FirmwareRevision = 22;
const int FirmwareSubRevision = 1;
const char* FirmwareDate = "27 Apr 2019";
const int FirmwareSubRevision = 2;
const char* FirmwareDate = "9 May 2019";
#ifdef ESP32
@ -145,6 +145,7 @@ void manageCyclicMode();
// DS18B20 temperature sensor support
OneWire ds(15); // on pin 5 (a 4.7K resistor is necessary)
DallasTemperature TempSensor(&ds);
DeviceAddress tempSensorAddress;
long lastTemperatureTime; // used to moderate DS18B20 access
float fFilteredTemperature = -100; // -100: force direct update uopn first pass
const float fAlpha = 0.95; // exponential mean alpha
@ -360,6 +361,11 @@ void setup() {
DebugPort.println(msg);
}
}
memset(tempSensorAddress, 0, 8);
if(numberOfDevices)
TempSensor.getAddress(tempSensorAddress, 0);
TempSensor.setWaitForConversion(false);
TempSensor.requestTemperatures();
lastTemperatureTime = millis();
@ -778,7 +784,7 @@ void loop()
tDelta = timenow - lastTemperatureTime;
if(tDelta > TEMPERATURE_INTERVAL) { // maintain a minimum holdoff period
lastTemperatureTime += TEMPERATURE_INTERVAL; // reset time to observe temeprature
fTemperature = TempSensor.getTempCByIndex(0); // read sensor
fTemperature = TempSensor.getTempC(tempSensorAddress); // read sensor
// DebugPort.print("DS18B20 = "); DebugPort.println(fTemperature);
// initialise filtered temperature upon very first pass
if(fTemperature > -80) { // avoid disconnected sensor readings being integrated

View file

@ -269,8 +269,8 @@ void updateJSONclients(bool report)
if (report) {
DebugPort.print("JSON send: "); DebugPort.println(jsonStr);
}
getBluetoothClient().send( jsonStr );
sendWebServerString( jsonStr );
getBluetoothClient().send( jsonStr );
}
}
// update extended params
@ -279,21 +279,28 @@ void updateJSONclients(bool report)
if (report) {
DebugPort.print("JSON send: "); DebugPort.println(jsonStr);
}
getBluetoothClient().send( jsonStr );
sendWebServerString( jsonStr );
getBluetoothClient().send( jsonStr );
}
}
// update timer parameters
bool bNewTimerInfo = false;
for(int tmr=0; tmr<14; tmr++)
{
unsigned long tStart = millis();
if(makeJSONTimerString(tmr, jsonStr, sizeof(jsonStr))) {
unsigned long tJSON = millis() - tStart;
if (report) {
DebugPort.print("JSON send: "); DebugPort.println(jsonStr);
}
getBluetoothClient().send( jsonStr );
tStart = millis();
sendWebServerString( jsonStr );
unsigned long tWF = millis() - tStart;
tStart = millis();
getBluetoothClient().send( jsonStr );
unsigned long tBT = millis() - tStart;
bNewTimerInfo = true;
DebugPort.print("JSON times : "); DebugPort.print(tJSON); DebugPort.print(",");DebugPort.print(tBT); DebugPort.print(",");DebugPort.println(tWF);
}
}
// request timer refesh upon clients
@ -309,8 +316,8 @@ void updateJSONclients(bool report)
root.printTo(jsonStr, 800);
DebugPort.print("JSON send: "); DebugPort.println(jsonStr);
getBluetoothClient().send( jsonStr );
sendWebServerString( jsonStr );
getBluetoothClient().send( jsonStr );
}
}

View file

@ -192,9 +192,14 @@ bool isWebServerClientChange()
bool sendWebServerString(const char* Str)
{
unsigned long tStart = millis();
if(webSocket.connectedClients()) {
unsigned long tCon = millis() - tStart;
tStart = millis();
bTxWebData = true; // OLED tx data animation flag
webSocket.broadcastTXT(Str);
unsigned long tWeb = millis() - tStart;
// DebugPort.print("Websend times : "); DebugPort.print(tCon); DebugPort.print(","); DebugPort.println(tWeb);
return true;
}
return false;