added support for ESP32 (untested)

This commit is contained in:
Chester 2021-03-14 15:38:59 +01:00
parent f6841f9f47
commit b076743f54
5 changed files with 71 additions and 32 deletions

View file

@ -43,8 +43,6 @@
#define MARCSTATE_RXTX_SWITCH 0x15 #define MARCSTATE_RXTX_SWITCH 0x15
#define MARCSTATE_TXFIFO_UNDERFLOW 0x16 #define MARCSTATE_TXFIFO_UNDERFLOW 0x16
#define CC1101_GDO0 D2 // GDO0 input interrupt pin
#define WRITE_BURST 0x40 #define WRITE_BURST 0x40
#define READ_SINGLE 0x80 #define READ_SINGLE 0x80
#define READ_BURST 0xC0 #define READ_BURST 0xC0

33
include/hwconfig.h Normal file
View file

@ -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__

View file

@ -8,15 +8,23 @@
; Please visit documentation for the other options and examples ; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html ; https://docs.platformio.org/page/projectconf.html
[env:nodemcuv2] [platformio]
platform = espressif8266 ;default_envs = esp8266-test
board = nodemcuv2 default_envs = esp32, esp8266
[env:esp32]
framework = arduino framework = arduino
platform = espressif32
board = az-delivery-devkit-v4
board_build.mcu = esp32
lib_deps = rweather/Crypto @ ^0.2.0
lib_deps = [env:esp8266]
Crypto framework = arduino
platform = espressif8266
board = d1_mini_lite
board_build.mcu = esp8266
lib_deps = rweather/Crypto @ ^0.2.0
; OTA ; OTA
upload_port = 10.0.0.86 ;upload_port = 10.0.0.86
#upload_port = 10.14.0.139 ;upload_protocol = espota
upload_protocol = espota

View file

@ -13,6 +13,7 @@
*/ */
#include "WaterMeter.h" #include "WaterMeter.h"
#include "hwconfig.h"
WaterMeter::WaterMeter() WaterMeter::WaterMeter()
{ {
@ -37,7 +38,7 @@ inline void WaterMeter::waitMiso(void)
} }
// write a single register of CC1101 // 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 selectCC1101(); // Select CC1101
waitMiso(); // Wait until MISO goes low waitMiso(); // Wait until MISO goes low
@ -47,7 +48,7 @@ void WaterMeter::writeReg(uint8 regAddr, uint8 value)
} }
// send a strobe command to CC1101 // send a strobe command to CC1101
void WaterMeter::cmdStrobe(uint8 cmd) void WaterMeter::cmdStrobe(uint8_t cmd)
{ {
selectCC1101(); // Select CC1101 selectCC1101(); // Select CC1101
delayMicroseconds(5); delayMicroseconds(5);
@ -58,9 +59,9 @@ void WaterMeter::cmdStrobe(uint8 cmd)
} }
// read CC1101 register (status or configuration) // 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; addr = regAddr | regType;
selectCC1101(); // Select CC1101 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; addr = regAddr | READ_BURST;
selectCC1101(); // Select CC1101 selectCC1101(); // Select CC1101

View file

@ -12,29 +12,28 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <ESP8266WiFi.h> #if defined(ESP8266)
#include <ESP8266mDNS.h> #include <ESP8266WiFi.h>
#include <SoftwareSerial.h> #include <ESP8266mDNS.h>
#include <WiFiUdp.h> #include <SoftwareSerial.h>
#elif defined(ESP32)
#include <WiFi.h>
#include <ESPmDNS.h>
#endif
#include <PubSubClient.h> #include <PubSubClient.h>
#include <ArduinoOTA.h> #include <ArduinoOTA.h>
#include "WaterMeter.h" #include "WaterMeter.h"
#include "credentials.h" #include "credentials.h"
#include "hwconfig.h"
#define ESP_NAME "ESP-Meter" #define ESP_NAME "WaterMeter"
// 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 DEBUG 0 #define DEBUG 0
#if defined(ESP32)
#define LED_BUILTIN 4
#endif
//Wifi settings: SSID, PW, MQTT broker //Wifi settings: SSID, PW, MQTT broker
#define NUM_SSID_CREDENTIALS 3 #define NUM_SSID_CREDENTIALS 3
const char *credentials[NUM_SSID_CREDENTIALS][4] = const char *credentials[NUM_SSID_CREDENTIALS][4] =