diff --git a/include/WaterMeter.h b/include/WaterMeter.h
index 597dc04..60821e2 100644
--- a/include/WaterMeter.h
+++ b/include/WaterMeter.h
@@ -43,8 +43,6 @@
#define MARCSTATE_RXTX_SWITCH 0x15
#define MARCSTATE_TXFIFO_UNDERFLOW 0x16
-#define CC1101_GDO0 D2 // GDO0 input interrupt pin
-
#define WRITE_BURST 0x40
#define READ_SINGLE 0x80
#define READ_BURST 0xC0
diff --git a/include/hwconfig.h b/include/hwconfig.h
new file mode 100644
index 0000000..dc97e52
--- /dev/null
+++ b/include/hwconfig.h
@@ -0,0 +1,33 @@
+#ifndef __HWCONFIG_H__
+#define __HWCONFIG_H__
+
+#if defined(ESP8266)
+// Attach CC1101 pins to ESP8266 SPI pins
+// VCC => 3V3
+// GND => GND
+// CSN => D8
+// MOSI => D7
+// MISO => D6
+// SCK => D5
+// GD0 => D2 A valid interrupt pin for your platform (defined below this)
+// GD2 => not connected
+ #define CC1101_GDO0 D2 // GDO0 input interrupt pin
+ #define PIN_LED_BUILTIN D4
+#elif defined(ESP32)
+// Attach CC1101 pins to ESP32 SPI pins
+// VCC => 3V3
+// GND => GND
+// CSN => 4
+// MOSI => 23
+// MISO => 19
+// SCK => 18
+// GD0 => 32 any valid interrupt pin for your platform will do
+// GD2 => not connected
+
+// attach CC1101 pins to ESP32 SPI pins
+
+ #define CC1101_GDO0 32
+ #define PIN_LED_BUILTIN 2
+#endif
+
+#endif //__HWCONFIG_H__
\ No newline at end of file
diff --git a/platformio.ini b/platformio.ini
index 5b6f598..aadf99b 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -8,15 +8,23 @@
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
-[env:nodemcuv2]
-platform = espressif8266
-board = nodemcuv2
+[platformio]
+;default_envs = esp8266-test
+default_envs = esp32, esp8266
+
+[env:esp32]
framework = arduino
+platform = espressif32
+board = az-delivery-devkit-v4
+board_build.mcu = esp32
+lib_deps = rweather/Crypto @ ^0.2.0
-lib_deps =
- Crypto
-
+[env:esp8266]
+framework = arduino
+platform = espressif8266
+board = d1_mini_lite
+board_build.mcu = esp8266
+lib_deps = rweather/Crypto @ ^0.2.0
; OTA
-upload_port = 10.0.0.86
-#upload_port = 10.14.0.139
-upload_protocol = espota
\ No newline at end of file
+;upload_port = 10.0.0.86
+;upload_protocol = espota
\ No newline at end of file
diff --git a/src/WaterMeter.cpp b/src/WaterMeter.cpp
index f55115d..7b1682e 100644
--- a/src/WaterMeter.cpp
+++ b/src/WaterMeter.cpp
@@ -13,6 +13,7 @@
*/
#include "WaterMeter.h"
+#include "hwconfig.h"
WaterMeter::WaterMeter()
{
@@ -37,7 +38,7 @@ inline void WaterMeter::waitMiso(void)
}
// write a single register of CC1101
-void WaterMeter::writeReg(uint8 regAddr, uint8 value)
+void WaterMeter::writeReg(uint8_t regAddr, uint8_t value)
{
selectCC1101(); // Select CC1101
waitMiso(); // Wait until MISO goes low
@@ -47,7 +48,7 @@ void WaterMeter::writeReg(uint8 regAddr, uint8 value)
}
// send a strobe command to CC1101
-void WaterMeter::cmdStrobe(uint8 cmd)
+void WaterMeter::cmdStrobe(uint8_t cmd)
{
selectCC1101(); // Select CC1101
delayMicroseconds(5);
@@ -58,9 +59,9 @@ void WaterMeter::cmdStrobe(uint8 cmd)
}
// read CC1101 register (status or configuration)
-uint8 WaterMeter::readReg(uint8 regAddr, uint8 regType)
+uint8_t WaterMeter::readReg(uint8_t regAddr, uint8_t regType)
{
- uint8 addr, val;
+ uint8_t addr, val;
addr = regAddr | regType;
selectCC1101(); // Select CC1101
@@ -73,9 +74,9 @@ uint8 WaterMeter::readReg(uint8 regAddr, uint8 regType)
}
//
-void WaterMeter::readBurstReg(uint8 * buffer, uint8 regAddr, uint8 len)
+void WaterMeter::readBurstReg(uint8_t * buffer, uint8_t regAddr, uint8_t len)
{
- uint8 addr, i;
+ uint8_t addr, i;
addr = regAddr | READ_BURST;
selectCC1101(); // Select CC1101
diff --git a/src/main.cpp b/src/main.cpp
index c3d307e..10283ad 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -12,29 +12,28 @@
along with this program. If not, see .
*/
-#include
-#include
-#include
-#include
+#if defined(ESP8266)
+ #include
+ #include
+ #include
+#elif defined(ESP32)
+ #include
+ #include
+#endif
#include
#include
#include "WaterMeter.h"
#include "credentials.h"
+#include "hwconfig.h"
-#define ESP_NAME "ESP-Meter"
-
-// Attach CC1101 pins to ESP8266 SPI pins
-// VCC => 3V3
-// GND => GND
-// CSN => D8
-// MOSI => D7
-// MISO => D6
-// SCK => D5
-// GD0 => D2 A valid interrupt pin for your platform (defined below this)
-// GD2 => not connected
+#define ESP_NAME "WaterMeter"
#define DEBUG 0
+#if defined(ESP32)
+ #define LED_BUILTIN 4
+#endif
+
//Wifi settings: SSID, PW, MQTT broker
#define NUM_SSID_CREDENTIALS 3
const char *credentials[NUM_SSID_CREDENTIALS][4] =