Skip to content
Snippets Groups Projects
Commit c8d4bfc6 authored by thiebolt's avatar thiebolt
Browse files

added SoftwareSerial port2 for esp8266 serial sensors. Tests required!

parent df552baf
No related branches found
No related tags found
No related merge requests found
...@@ -154,9 +154,17 @@ ...@@ -154,9 +154,17 @@
*/ */
#ifndef SENSORS_SERIAL_LINK #ifndef SENSORS_SERIAL_LINK
#ifdef ESP32 #ifdef ESP32
#define SENSORS_SERIAL_LINK (uint8_t)2 // [jul.21] neOSensor V5 added (i.e Serial2) #define SENSORS_SERIAL_LINK (uint8_t)2 // [jul.21] neOSensor V5 added (i.e Serial2)
#else #elif defined(ESP8266)
#define SENSORS_SERIAL_LINK INVALID_SERIAL_LINK /* [apr.22] notes about serial ports on esp8266
* - serial0(HW) is for programming and debug
* - serial1(HW) only TX
* - serial2(sw) this one
*/
//#define SENSORS_SERIAL_LINK INVALID_SERIAL_LINK
#define SENSORS_SERIAL_LINK (uint8_t)2 // [apr.22] useless but just to have var defined (i.e Serial2)
#define SENSORS_SERIAL_LINK_RX 4 // shared with PIR sensor hence avoid double declaration ;)
#define SENSORS_SERIAL_LINK_TX INVALID_GPIO // no TX pin
#endif #endif
#endif #endif
......
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
* Includes * Includes
*/ */
#include <Arduino.h> #include <Arduino.h>
#ifdef ESP8266
#include <SoftwareSerial.h>
#endif /* ESP8266 */
#include "neocampus.h" #include "neocampus.h"
#include "neocampus_debug.h" #include "neocampus_debug.h"
...@@ -65,7 +68,7 @@ pm_serial::pm_serial( void ) : generic_driver( _MEASURES_INTERLEAVE_MS, ...@@ -65,7 +68,7 @@ pm_serial::pm_serial( void ) : generic_driver( _MEASURES_INTERLEAVE_MS,
_measures = nullptr; _measures = nullptr;
_nbMeasures = 0; _nbMeasures = 0;
/* [nov.21] we choose to disable PM%_ENABLE gpio because PMS sensors /* [nov.21] we choose to disable PM_ENABLE gpio because PMS sensors
* already features both sleep() and wakeUp() commands * already features both sleep() and wakeUp() commands
_enable_gpio = PM_ENABLE; // PM_ENABLE gpio _enable_gpio = PM_ENABLE; // PM_ENABLE gpio
*/ */
...@@ -700,12 +703,18 @@ boolean pm_serial::_init( void ) { ...@@ -700,12 +703,18 @@ boolean pm_serial::_init( void ) {
return false; return false;
} }
#warning "esp8266 hack: Serial2 is not known ... correct me!" #if defined(ESP8266)
#ifndef ESP8266 #warning "esp8266 serial2 makes use of SoftwareSerial!"
Serial2.begin( _link_speed ); SoftwareSerial *mySerial2 = new SoftwareSerial(SENSORS_SERIAL_LINK_RX,SENSORS_SERIAL_LINK_TX);
_stream = &Serial2; // TODO pointer to stream according to link number specified ... maybe later ;) if( !mySerial2 ) return false;
mySerial2->begin( _link_speed );
_stream = mySerial2;
#elif defined(ESP32)
Serial2.begin( _link_speed );
_stream = &Serial2; // TODO pointer to stream according to link number specified ... maybe later ;)
#else #else
return false; #warning "unknown architecture for Serial2 link"
return false;
#endif /* ESP8266 */ #endif /* ESP8266 */
if( !_stream ) return false; if( !_stream ) return false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment