+
+#include "sensorState.h"
+
+static const char * ERROR_LOG_NAME = "/sensor_error.txt";
+static const char * UNKNOWN_SENSOR = "unknown sensor";
+
+OneWire ds( SENSOR_PIN );
+Preferences sensorPreferences;
+
+sensorState::sensorState() {}
+sensorState::~sensorState() {}
+
+bool sensorState::startSensors() {
+ if ( nullptr != _pSensorState ) {
+ ESP_LOGE( TAG, "Sensors already running. Exiting." );
+ return false;
+ }
+ _pSensorState = new sensorState();
+ if ( nullptr == _pSensorState ) {
+ ESP_LOGE( TAG, "Sensors not created. (low mem?) Exiting." );
+ return false;
+ }
+ sensorPreferences.begin( "sensors", false );
+ _pSensorState->setStackSize(3500);
+ _pSensorState->setCore(1);
+ _pSensorState->setPriority(0);
+ _pSensorState->start();
+ return true;
+}
+
+void sensorState::rescan() {
+ _pSensorState->_rescan = true;
+}
+
+uint8_t sensorState::count() {
+ return ( nullptr == _pSensorState ) ? 0 : _pSensorState->_count;
+};
+
+float sensorState::temp( const uint8_t num ) {
+ return ( nullptr == _pSensorState ) ? NAN : _pSensorState->_state[num].tempCelsius;
+};
+
+bool sensorState::error( const uint8_t num ) {
+ return ( nullptr == _pSensorState ) ? true : _pSensorState->_state[num].error;
+};
+
+const char * sensorState::getName( const uint8_t num, sensorName_t &name ) {
+ if ( nullptr == _pSensorState ) return name;
+ sensorId_t id;
+ getId( num, id );
+ return getName( id, name );
+}
+
+const char * sensorState::getName( const sensorName_t &id, sensorName_t &name ){
+ if ( nullptr == _pSensorState ) return name;
+ String result = sensorPreferences.getString( id, UNKNOWN_SENSOR );
+ if ( result ) strncpy( name, result.c_str(), sizeof( sensorName_t ) );
+ return name;
+}
+
+const char * sensorState::getId( const uint8_t num, sensorId_t &id ) {
+ if ( nullptr == _pSensorState ) return id;
+ snprintf( id, sizeof( sensorId_t ), "%02x%02x%02x%02x%02x%02x%02x",
+ _pSensorState->_state[num].addr[1], _pSensorState->_state[num].addr[2], _pSensorState->_state[num].addr[3], _pSensorState->_state[num].addr[4],
+ _pSensorState->_state[num].addr[5], _pSensorState->_state[num].addr[6], _pSensorState->_state[num].addr[7] );
+ return id;
+}
+
+bool sensorState::setName( const sensorId_t &id, const char * name ) {
+ if ( 0 == strlen( name ) ) return sensorPreferences.remove( id );
+ if ( strlen( name ) > sizeof( sensorName_t ) ) return false;
+ return sensorPreferences.putString( id, name );
+}
+
+bool sensorState::logging() {
+ return ( nullptr == _pSensorState ) ? false : sensorPreferences.getBool( "logging", false );
+}
+
+bool sensorState::setLogging( const bool state ) {
+ return ( nullptr == _pSensorState ) ? false : sensorPreferences.putBool( "logging", state );
+};
+
+bool sensorState::errorLogging() {
+ return ( nullptr == _pSensorState ) ? false : _pSensorState->_errorlogging;
+};
+
+void sensorState::setErrorLogging( const bool state ) {
+ if ( nullptr != _pSensorState ) _pSensorState->_errorlogging = state;
+};
+
+void sensorState::run( void * data ) {
+ uint8_t loopCounter = _scanSensors();
+ ESP_LOGI( TAG, "Sensors scanned: %i found.", loopCounter );
+ while (1)
+ {
+ ESP_LOGD( TAG, "Stack watermark: %i", uxTaskGetStackHighWaterMark( NULL ) );
+ if ( _rescan ) loopCounter = _scanSensors();
+
+ ds.reset();
+ ds.write( 0xCC, 0); /* Skip ROM - All sensors */
+ ds.write( 0x44, 0); /* start conversion, with parasite power off at the end */
+
+ vTaskDelay( 750 ); //wait for conversion ready
+
+ uint8_t num = 0;
+ while ( num < loopCounter )
+ {
+ byte data[12];
+
+ _tempState[num].error = true; /* we start with an error, which will be cleared if the CRC checks out. */
+ ds.reset();
+ ds.select( _tempState[num].addr );
+ ds.write( 0xBE ); /* Read Scratchpad */
+ for ( byte i = 0; i < 9; i++ ) data[i] = ds.read(); // we need 9 bytes
+
+ ESP_LOGD( TAG, "Sensor %i '%s' data=%02x%02x%02x%02x%02x%02x%02x%02x%02x", num, _tempState[num].name,
+ data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8] );
+
+ byte type_s;
+ // the first ROM byte indicates which chip
+ switch ( _tempState[num].addr[0] )
+ {
+ case 0x10:
+ ESP_LOGD( TAG, "Dallas sensor type : DS18S20" ); /* or old DS1820 */
+ type_s = 1;
+ break;
+ case 0x28:
+ ESP_LOGD( TAG, "Dallas sensor type : DS18B20");
+ type_s = 0;
+ break;
+ case 0x22:
+ ESP_LOGD( TAG, "Dallas sensor type : DS1822");
+ type_s = 0;
+ break;
+ default:
+ ESP_LOGE( TAG, "OneWire device is not a DS18x20 family device.");
+ }
+
+ if ( OneWire::crc8( data, 8 ) != data[8] )
+ {
+ _tempState[num].error = true;
+ _tempState[num].tempCelsius = NAN;
+ if ( _errorlogging && !_logError( num, ERROR_LOG_NAME, "BAD_CRC", data ) )
+ ESP_LOGE( TAG, "%s", "Error writing errorlog.(disk full?)" );
+ }
+ else
+ {
+ int16_t raw = (data[1] << 8) | data[0];
+ if (type_s)
+ {
+ raw = raw << 3; // 9 bit resolution default
+ if (data[7] == 0x10)
+ {
+ // "count remain" gives full 12 bit resolution
+ raw = (raw & 0xFFF0) + 12 - data[6];
+ }
+ }
+ else
+ {
+ byte cfg = (data[4] & 0x60);
+ // at lower res, the low bits are undefined, so let's zero them
+ if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
+ else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
+ else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
+ //// default is 12 bit resolution, 750 ms conversion time
+ }
+ _tempState[num].tempCelsius = raw / 16.0;
+
+ if ( _tempState[num].tempCelsius > -55.0 && _tempState[num].tempCelsius < 85.0 )
+ {
+ _tempState[num].error = false;
+ }
+ else
+ {
+ _tempState[num].error = true;
+ _tempState[num].tempCelsius = NAN;
+ if ( _errorlogging && !_logError( num, ERROR_LOG_NAME, "BAD_TMP", data ) )
+ ESP_LOGE( TAG, "%s", "Error writing errorlog.(disk full?)" );
+ }
+ }
+ ESP_LOGD( TAG, "sensor %i: %.1f %s", num, _tempState[num].tempCelsius, _tempState[num].error ? "invalid" : "valid" );
+ num++;
+ }
+ memcpy( &_state, &_tempState, sizeof( sensorState_t[ MAX_NUMBER_OF_SENSORS ] ) );
+ _count = loopCounter;
+ }
+}
+
+uint8_t sensorState::_scanSensors() {
+ uint8_t num = 0;
+ byte currentAddr[ sizeof( sensorState_t::addr ) ];
+
+ ds.reset_search();
+ ds.target_search(0x28);
+ vTaskPrioritySet( NULL, 10);
+ while ( ds.search( currentAddr ) && ( num < MAX_NUMBER_OF_SENSORS ) )
+ {
+ _tempState[num].error = true;
+ _tempState[num].tempCelsius = NAN;
+ memcpy( _tempState[num].addr, currentAddr, sizeof( sensorState_t::addr ) );
+ num++;
+ }
+ vTaskPrioritySet( NULL, 0);
+ _rescan = false;
+ return num;
+}
+
+bool sensorState::_logError( const uint8_t num, const char * path, const char * message, const byte data[9] )
+{
+ File file = FFat.open( path, FILE_APPEND );
+ if ( !file ) return false;
+
+ time_t rawtime;
+ struct tm * timeinfo;
+ time ( &rawtime );
+ timeinfo = localtime ( &rawtime );
+ char timeBuff[20];
+ strftime ( timeBuff, sizeof( timeBuff ), "%x %X", timeinfo );
+ char buffer[100];
+ snprintf( buffer, sizeof( buffer ), "%s - sensor:%i %s %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X", timeBuff, num, message,
+ data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8] );
+ ESP_LOGD( TAG, "%s", buffer );
+
+ if ( !file.println( buffer ) )
+ {
+ file.close();
+ return false;
+ }
+ file.close();
+ return true;
+}
diff --git a/sensorState.h b/sensorState.h
new file mode 100644
index 0000000..832fe14
--- /dev/null
+++ b/sensorState.h
@@ -0,0 +1,60 @@
+#ifndef SENSORSTATE_H
+#define SENSORSTATE_H
+
+#ifndef ESP32
+#warning sensorState will only work on ESP32 MCUs
+#endif
+
+#include "Task.h"
+
+#define SAVED_LOGFILES 30
+#define SENSOR_PIN 5
+#define MAX_NUMBER_OF_SENSORS 3
+
+#define VALID_ID_LENGTH 14
+
+typedef char sensorId_t[VALID_ID_LENGTH + 1];
+typedef char sensorName_t[15];
+
+class sensorState: public Task {
+
+ public:
+
+ struct sensorState_t /* struct to keep track of Dallas DS18B20 sensors */
+ {
+ byte addr[8] = {};
+ float tempCelsius = NAN;
+ bool error = true;
+ };
+
+ sensorState();
+ virtual ~sensorState();
+
+ bool startSensors();
+ void rescan();
+ uint8_t count();
+ float temp( const uint8_t num );
+ bool error( const uint8_t num );
+ const char * getName( const uint8_t num, sensorName_t &name );
+ const char * getName( const sensorName_t &id, sensorName_t &name );
+ const char * getId( const uint8_t num, sensorId_t &id );
+ bool setName( const sensorId_t &id, const char * name );
+ bool logging();
+ bool setLogging( const bool state );
+ bool errorLogging();
+ void setErrorLogging( const bool state );
+
+ private:
+
+ void run( void * data );
+ uint8_t _count = 0;
+ uint8_t _scanSensors();
+ sensorState_t _state[MAX_NUMBER_OF_SENSORS];
+ sensorState_t _tempState[MAX_NUMBER_OF_SENSORS];
+ sensorState * _pSensorState = nullptr;
+ bool _errorlogging = false;
+ bool _logError( const uint8_t num, const char * path, const char * message, const byte data[9] );
+ bool _rescan = false;
+};
+
+#endif //SENSORSTATE_H
diff --git a/temptask.ino b/temptask.ino
deleted file mode 100644
index 91d1119..0000000
--- a/temptask.ino
+++ /dev/null
@@ -1,119 +0,0 @@
-void IRAM_ATTR tempTask( void * pvParameters )
-{
- OneWire ds( ONEWIRE_PIN ); /* a 4.7K pull-up resistor is necessary */
-
- numberOfFoundSensors = 0;
- byte currentAddr[8];
-
- while ( ds.search( currentAddr ) && numberOfFoundSensors < MAX_NUMBER_OF_SENSORS )
- {
- for ( uint8_t i = 0; i < sizeof( currentAddr ); i++)
- {
- sensor[numberOfFoundSensors].addr[i] = currentAddr[i];
- }
- /* make a key field -in sensorUniqueId- for NVS */
- char sensorUniqueId[17];
- snprintf( sensorUniqueId, sizeof( sensorUniqueId ), "%02x%02x%02x%02x%02x%02x%02x",
- currentAddr[1], currentAddr[2], currentAddr[3], currentAddr[4], currentAddr[5], currentAddr[6], currentAddr[7] );
-
- ESP_LOGI( TAG, "Finding saved name for sensor ID: %s", sensorUniqueId );
-
- /* and read value from NVS or use default name */
- snprintf( sensor[numberOfFoundSensors].name, sizeof( sensor[numberOfFoundSensors].name ),
- preferences.getString( sensorUniqueId, "temp sensor" ).c_str(), numberOfFoundSensors );
-
- ESP_LOGD( TAG, "Sensor %i ID: %s - Name: '%s'", numberOfFoundSensors, sensorUniqueId, sensor[numberOfFoundSensors].name );
-
- numberOfFoundSensors++;
- }
- ESP_LOGI( TAG, "%i Dallas sensors found.", numberOfFoundSensors );
-
- if ( !numberOfFoundSensors )
- {
- vTaskDelete( NULL );
- }
-
- /* main temptask loop */
-
- while (1)
- {
- ds.reset();
- ds.write( 0xCC, 0); /* Skip ROM - All sensors */
- ds.write( 0x44, 0); /* start conversion, with parasite power off at the end */
-
- vTaskDelay( 750 / portTICK_PERIOD_MS); //wait for conversion ready
-
-
- for ( byte thisSensor = 0; thisSensor < numberOfFoundSensors; thisSensor++)
- {
- byte data[12];
-
- ds.reset();
- ds.select( sensor[thisSensor].addr );
- ds.write( 0xBE ); /* Read Scratchpad */
- for ( byte i = 0; i < 9; i++)
- { // we need 9 bytes
- data[i] = ds.read( );
- }
-
-
- ESP_LOGD( TAG, "Sensor %i '%s' data=%02x%02x%02x%02x%02x%02x%02x%02x%02x", thisSensor, sensor[thisSensor].name,
- data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8] );
-
- byte type_s;
- // the first ROM byte indicates which chip
- switch ( sensor[thisSensor].addr[0] )
- {
- case 0x10:
- ESP_LOGD( TAG, "Dallas sensor type : DS18S20" ); /* or old DS1820 */
- type_s = 1;
- break;
- case 0x28:
- ESP_LOGD( TAG, "Dallas sensor type : DS18B20");
- type_s = 0;
- break;
- case 0x22:
- ESP_LOGD( TAG, "Dallas sensor type : DS1822");
- type_s = 0;
- break;
- default:
- ESP_LOGE( TAG, "OneWire device is not a DS18x20 family device.");
- }
-
- int16_t raw;
- if ( data[8] == 0xFF || OneWire::crc8(data, 8) != data[8])
- {
-
- // CRC of temperature reading indicates an error, so we print a error message and discard this reading
- sensor[thisSensor].error = true;
- if ( LOG_SENSOR_ERRORS ) writeSensorErrorLog( thisSensor, "BAD_CRC", data );
- ESP_LOGE( TAG, "Sensor %i error. data: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X", thisSensor, data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8] );
- }
- else
- {
- raw = (data[1] << 8) | data[0];
- if (type_s)
- {
- raw = raw << 3; // 9 bit resolution default
- if (data[7] == 0x10)
- {
- // "count remain" gives full 12 bit resolution
- raw = (raw & 0xFFF0) + 12 - data[6];
- }
- }
- else
- {
- byte cfg = (data[4] & 0x60);
- // at lower res, the low bits are undefined, so let's zero them
- if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
- else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
- else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
- //// default is 12 bit resolution, 750 ms conversion time
-
- }
- sensor[thisSensor].tempCelcius = raw / 16.0;
- sensor[thisSensor].error = false;
- }
- }
- }
-}
diff --git a/tfttask.ino b/tfttask.ino
index 5ec804e..e6833f1 100644
--- a/tfttask.ino
+++ b/tfttask.ino
@@ -108,6 +108,8 @@ displayState tftState = normal;
bool tftClearScreen = true;
+void drawSensors();
+
void IRAM_ATTR tftTask( void * pvParameters )
{
const TickType_t tftTaskdelayTime = ( 1000 / UPDATE_FREQ_TFT) / portTICK_PERIOD_MS;
@@ -222,6 +224,33 @@ static inline __attribute__((always_inline)) void showMenu()
}
}
+void newSensors()
+{
+ tft.startWrite();
+ tft.writeFillRect( 210, 60, TFT_BUTTON_WIDTH, 120, TFT_BACK_COLOR );
+ tft.endWrite();
+
+ sensorName_t sensorName;
+ for ( uint8_t num = 0; num < sensor.count(); num++ )
+ {
+ tempArea[num].x = 220;
+ tempArea[num].y = 70 + num * 40;
+ tempArea[num].w = TFT_BUTTON_WIDTH - 20;
+ tempArea[num].h = 30;
+ tempArea[num].color = TFT_BACK_COLOR;
+ tempArea[num].labelcolor = ILI9341_WHITE;
+ tempArea[num].fontsize = size2;
+ button.updateSensorLabel( tempArea[num], (char *)sensor.getName( num, sensorName ) );
+ }
+}
+
+void updateSensorLabels( )
+{
+ sensorName_t sensorName;
+ for ( uint8_t thisSensor = 0; thisSensor < sensor.count(); thisSensor++ )
+ button.updateSensorLabel( tempArea[thisSensor], (char *)sensor.getName( thisSensor, sensorName ) );
+}
+
static inline __attribute__((always_inline)) void showStatus()
{
const uint16_t BARS_BOTTOM = 190;
@@ -235,50 +264,12 @@ static inline __attribute__((always_inline)) void showStatus()
uint16_t channelColor565[NUMBER_OF_CHANNELS];
-
if ( tftClearScreen )
{
tft.fillScreen( TFT_BACK_COLOR );
button.draw( MENU_BUTTON );
-
showIPAddress( );
displayedWiFiStatus = WiFi.status();
-
- tft.setTextSize( 0 );
- for ( uint8_t thisSensor = 0; thisSensor < numberOfFoundSensors; thisSensor++ )
- {
- tempArea[thisSensor].x = 220;
- tempArea[thisSensor].y = 70 + thisSensor * 50;
- tempArea[thisSensor].w = TFT_BUTTON_WIDTH - 20;
- tempArea[thisSensor].h = 30;
- tempArea[thisSensor].color = TFT_BACK_COLOR;
- tempArea[thisSensor].labelcolor = ILI9341_WHITE;
- tempArea[thisSensor].fontsize = size2;
- button.updateSensorLabel( tempArea[thisSensor], sensor[thisSensor].name );
- }
- drawSensors( true );
- }
-
- if ( numberOfFoundSensors && !tftClearScreen )
- {
- struct savedSensor_t
- {
- char name[ sizeof( sensor->name ) ];
- };
-
- static savedSensor_t savedSensor[MAX_NUMBER_OF_SENSORS];
-
- for ( auto thisSensor = 0; thisSensor < numberOfFoundSensors; thisSensor++ )
- {
- if ( strcmp( sensor[thisSensor].name, savedSensor[thisSensor].name ) != 0 )
- {
- ESP_LOGI( TAG, "Updating sensor %i label from '%s' to '%s'.", thisSensor, savedSensor[thisSensor].name, sensor[thisSensor].name );
-
- button.updateSensorLabel( tempArea[thisSensor], sensor[thisSensor].name );
-
- strncpy( savedSensor[thisSensor].name, sensor[thisSensor].name, sizeof( sensor->name ) );
- }
- }
}
static float oldPercentage[NUMBER_OF_CHANNELS];
@@ -356,7 +347,6 @@ static inline __attribute__((always_inline)) void showStatus()
oldPercentage[ channelNumber ] = channel[channelNumber].currentPercentage;
averageLedBrightness += ledcRead( channelNumber );
}
- tftClearScreen = false;
averageLedBrightness = averageLedBrightness / NUMBER_OF_CHANNELS;
@@ -364,7 +354,38 @@ static inline __attribute__((always_inline)) void showStatus()
ledcWrite( TFT_BACKLIGHT_CHANNEL, ( averageLedBrightness > rawBrightness ) ? rawBrightness : averageLedBrightness );
- drawSensors( false );
+ static uint8_t lastCount{0};
+ static sensorName_t displayedName[MAX_NUMBER_OF_SENSORS];
+ static float displayedTemp[MAX_NUMBER_OF_SENSORS];
+
+ if ( tftClearScreen || sensor.count() != lastCount )
+ {
+ memset( displayedName, 0, sizeof( displayedName ) );
+ newSensors();
+ lastCount = sensor.count();
+ }
+
+ for ( uint8_t num = 0; num < sensor.count(); num++ )
+ {
+ //if the name changed update the display
+ sensorName_t name;
+ sensor.getName( num, name );
+ if ( tftClearScreen || strcmp( displayedName[num], name ) )
+ {
+ button.updateSensorLabel( tempArea[num], name );
+ memcpy( displayedName[num], name, sizeof( sensorName_t ) );
+ }
+
+ // if the temperature changed update the display
+ if ( tftClearScreen || displayedTemp[num] != sensor.temp( num ) )
+ {
+ snprintf( tempArea[num].text, sizeof( tempArea[num].text ), " %.1f%c ", sensor.temp( num ), char(247) );
+ button.updateText( tempArea[num] );
+ displayedTemp[num] = sensor.temp( num );
+ }
+ }
+
+ tftClearScreen = false;
struct tm timeinfo;
@@ -435,7 +456,6 @@ static inline __attribute__((always_inline)) void drawMenuButtons()
button.draw( EXIT_BUTTON );
}
-
static inline __attribute__((always_inline)) uint16_t mapUint16( const uint16_t &x, const uint16_t &in_min, const uint16_t &in_max, const uint16_t &out_min, const uint16_t &out_max)
{
return ( x - in_min ) * ( out_max - out_min ) / ( in_max - in_min ) + out_min;
@@ -491,33 +511,11 @@ static inline __attribute__((always_inline)) void showIPAddress( )
tft.print( buff );
}
-void drawSensors( const bool &forceDraw )
+void drawSensors()
{
- if ( numberOfFoundSensors )
- {
- static float currentTemp[MAX_NUMBER_OF_SENSORS];
-
- for ( uint8_t thisSensor = 0; thisSensor < numberOfFoundSensors; thisSensor++ )
- {
- if ( sensor[ thisSensor ].tempCelcius != currentTemp[ thisSensor ] || sensor[thisSensor].error || forceDraw ) /* only update temp if changed */
- {
- if ( sensor[ thisSensor ].error )
- {
- tempArea[thisSensor].labelcolor = ILI9341_YELLOW; /* show temp as in error */
- snprintf( tempArea[thisSensor].text, sizeof( tempArea[thisSensor].text ), " ERROR " );
- button.updateText( tempArea[thisSensor] );
- currentTemp[thisSensor] = -273;
- return;
- }
- else
- {
- snprintf( tempArea[thisSensor].text, sizeof( tempArea[thisSensor].text ), " %.1f%c ", sensor[thisSensor].tempCelcius, char(247) );
- button.updateText( tempArea[thisSensor] );
- }
- }
- currentTemp[ thisSensor ] = sensor[ thisSensor ].tempCelcius;
- }
- }
+ sensorName_t sensorName;
+ for ( uint8_t thisSensor = 0; thisSensor < sensor.count(); thisSensor++ )
+ button.updateSensorLabel( tempArea[thisSensor], (char *)sensor.getName( thisSensor, sensorName ) );
}
//tftButton:: functions
diff --git a/webif/index.htm b/webif/index.htm
index 82a2857..4f92f6a 100644
--- a/webif/index.htm
+++ b/webif/index.htm
@@ -133,25 +133,22 @@
while ( channelValue[sensorNumber + 7].length > 0 )
{
var temp = channelValue[sensorNumber + 7].split(",");
- console.log(temp);
- if ( temp[1] != "ERROR" )
- str += String( '' + temp[0].toLowerCase() + "
" + temp[1].substring( 0, temp[1].indexOf( "." ) + 2 ) + "°
" );
- else
- str += String( '' + temp[0].toLowerCase() + "
ERROR
" );
+ console.log(temp);
+ str += String( '' + temp[0].toLowerCase() + "
" + temp[1].substring( 0, temp[1].indexOf( "." ) + 2 ) + "°
" );
sensorNumber++;
}
- if (str.length)
+ if (sensorNumber)
{
- $( "#tempBox" ).show();
$( "#tempStats" ).html( str );
+ $( "#tempBox" ).show();
}
+ else
+ $( "#tempBox" ).hide();
});
}
HOMECHANNELSSETUPEDITOR LOGS FILE MANAGER
-
-
Loading...
-
+Loading...
@@ -175,50 +172,47 @@
Loading...
$( document ).ready( function() {
// get the hostname, then the channelcolors and finally the channelnames
$.get( "/api/getdevice?hostname=")
- .done(function( data ){
- $( "#hostName" ).html( data );
- document.title = data.toUpperCase();
- })
- .fail(function(){
- console.log("failed getting hostname");
- })
- .always(function(){
- getChannelColors();
- });
+ .done(function( data ){
+ $( "#hostName" ).html( data );
+ document.title = data.toUpperCase();
+ })
+ .fail(function(){
+ console.log("failed getting hostname");
+ })
+ .always(function(){
+ getChannelColors();
+ });
});
-
-//functions
function getChannelColors(){
$.get( "/api/getdevice?channelcolors=" )
- .done(function( data ){
- channelColor = data.split("\n");
- channelColor.forEach( function( item, index ){
- $('.bar').eq(index).css( { 'background-color': item, 'box-shadow': "0px 0px 43px 0px " + item } );
- })
- })
- .fail(function(){
- console.log("failed getting channelcolors");
+ .done(function( data ){
+ channelColor = data.split("\n");
+ channelColor.forEach( function( item, index ){
+ $('.bar').eq(index).css( { 'background-color': item, 'box-shadow': "0px 0px 43px 0px " + item } );
})
- .always(function(){
- getChannelNames();
- });
+ })
+ .fail(function(){
+ console.log("failed getting channelcolors");
+ })
+ .always(function(){
+ getChannelNames();
+ });
}
-
function getChannelNames(){
$.get( "/api/getdevice?channelnames=" )
- .done(function( data ){
- var channelNames = data.split("\n");
- channelNames.forEach( function( item, index ){
- $('.name p').eq(index).html( item.trim() );
- })
- })
- .fail(function(){
- console.log("failed getting channelnames");
+ .done(function( data ){
+ var channelNames = data.split("\n");
+ channelNames.forEach( function( item, index ){
+ $('.name p').eq(index).html( item.trim() );
})
- .always(function(){
- updateBargraph();
- repeatTimer = setInterval( updateBargraph, 1000 ); //done with getting stuff
- });
+ })
+ .fail(function(){
+ console.log("failed getting channelnames");
+ })
+ .always(function(){
+ updateBargraph();
+ repeatTimer = setInterval( updateBargraph, 1000 ); //done with getting stuff
+ });
}