diff --git a/README.md b/README.md
index 1bbf08b..22a12a7 100644
--- a/README.md
+++ b/README.md
@@ -7,32 +7,37 @@ ESP32 Arduino IDE library for managing OneWire DS18B20 temperature sensors.
Just set the number of desired sensors and a GPIO pin number and you are good to go.
#### An simple interface for OneWire DS18B20 sensors.
+
- `logger.startSensors( 3, 5 )`
Starts max 3 sensors on GPIO 5 that are scanned and updated every 750ms.
+- `logger.startSensors( 3, 5, 1 )`
+
Starts max 3 sensors on GPIO 5 that are scanned and updated every 750ms.
+
Use ESP32 HW timer 1. If no timer number is given, timer 0 will be used.
- `logger.sensorCount()`
Get the number of sensors actually connected.
- `logger.getSensorTemp( 0 )`
Get a temperature reading from the first sensor.
#### With easy temperature logging to FFat.
+
- `sensor.startTempLogging( 180 )`
Starts temperature logging to FFat every 180 seconds.
-
The interval and log state are saved in NVS.
-
If after a reboot `startSensors()` is called logging will resume with the specified interval.
+
The interval and log state are saved in NVS.
+
If after a reboot `startSensors()` is called logging will resume with the specified interval.
- `sensor.stopTempLogging()`
-
Stops temperature logging to FFat.
+
Stops temperature logging to FFat.
- `sensor.isTempLogging()`
Gives the current temperature logging state.
-Temperature logging writes to a csv file formatted as `1970-01-01.log` if no system time is set before.
-
Logging is based on UTC. A typical log entry looks like:
+Temperature logging writes to a csv file formatted as `1970-01-01.log` if no system time is set before. Logging is based on UTC. A typical log entry looks like:
+
````bash
1564356928,26.69,23.00,18.44
````
-- Where `1564356928` is `Mon Jul 29 2019 01:35:28 GMT+0200 (Central European Summer Time)`
-
JS `Date` is the number of milliseconds since 01-01-1970 while the UNIX time is the number of seconds since then.
-
So to process these time values with JavaScript just take the UNIX time value and multiply it with 1000 to get a valid JS `Date` object.
-
In a console this would be: `new Date( 1564356928 * 1000 )`
+
+- The number `1564356928` is the Unix time `Mon Jul 29 2019 01:35:28 GMT+0200` when used in JS as: `new Date( 1564356928 * 1000 )`.
+
Because JS `Date` is the number of milliseconds since 01-01-1970 while the UNIX time is the number of seconds since then.
+
So to process these time values with JavaScript just take the UNIX time value and multiply it with 1000 to get a valid JS `Date` object. (with a one second resolution ofcourse)
- `26.69,23.00,18.44` are the logged sensor temperatures at that time.
- A start marker is written to the log file every time sensors are started.
A start marker looks like `#1572769710,FFatSensor start` where the number is a UNIX timestamp.
@@ -54,8 +59,7 @@ FFatSensor runs fine without FFat partition mounted, but then you have no loggin
#### Depends on:
- ESP32 FFat library. (only needed to log to file)
-- ESP32 [OneWire](https://github.com/stickbreaker/OneWire) library by Chuck Todd.
-
Use this library instead of the standard Arduino version which will not work for ESP32 MCUs.
+- ESP32 [OneWire](https://github.com/stickbreaker/OneWire) library by Chuck Todd. Use this library instead of the standard Arduino version which will not work for ESP32 MCUs.
- ESP32 [Task](https://github.com/CelliesProjects/Task) by Neil Kolban.
#### How to use:
diff --git a/src/FFatSensor.cpp b/src/FFatSensor.cpp
index 48fe9c8..49ceb05 100644
--- a/src/FFatSensor.cpp
+++ b/src/FFatSensor.cpp
@@ -78,7 +78,7 @@ static inline bool _saveTempLogStateToNVS( const bool state ) {
FFatSensor::FFatSensor() {}
FFatSensor::~FFatSensor() {}
-bool FFatSensor::startSensors( const uint8_t num, const uint8_t pin ) {
+bool FFatSensor::startSensors( const uint8_t num, const uint8_t pin, const uint8_t hw_timer ) {
if ( nullptr != _wire ) {
ESP_LOGE( TAG, "Sensors already running. Exiting." );
return false;
@@ -102,6 +102,7 @@ bool FFatSensor::startSensors( const uint8_t num, const uint8_t pin ) {
return false;
}
_maxSensors = num;
+ _hw_timer = hw_timer;
ESP_LOGD( TAG, "Created %i sensor objects.", num );
sensorPreferences.begin( NVSKEY_NAMESPACE, false );
@@ -154,7 +155,7 @@ bool FFatSensor::startTempLogging() {
bool FFatSensor::startTempLogging( const uint32_t seconds ) {
if ( NULL != tempLogTimer ) return false;
sensorPreferences.putULong( NVSKEY_INTERVAL, seconds );
- tempLogTimer = timerBegin(0, 80, true);
+ tempLogTimer = timerBegin(_hw_timer, 80, true);
timerAttachInterrupt(tempLogTimer, &_onTimer, true);
timerAlarmWrite(tempLogTimer, seconds * 1000000, true);
timerAlarmEnable(tempLogTimer);
diff --git a/src/FFatSensor.h b/src/FFatSensor.h
index 5750fa8..e2fd56b 100644
--- a/src/FFatSensor.h
+++ b/src/FFatSensor.h
@@ -31,7 +31,7 @@ class FFatSensor: public Task {
FFatSensor();
virtual ~FFatSensor();
/*sensor routines */
- bool startSensors( const uint8_t num, const uint8_t pin );
+ bool startSensors( const uint8_t num, const uint8_t pin, const uint8_t hw_timer=0 );
void rescanSensors();
uint8_t sensorCount() { return _count; };
float sensorTemp( const uint8_t num ) { return _state[num].tempCelsius; };
@@ -53,6 +53,7 @@ class FFatSensor: public Task {
const char * timeStamp( const timeStamp_t type , timeStampBuffer_t &tsb );
private:
+ uint8_t _hw_timer = 0;
uint8_t _maxSensors = 0;
uint8_t _count = 0;
sensorState_t * _state = nullptr;