Merge branch 'main' of git.starbeamrainbowlabs.com:sbrl/autoplant into main
This commit is contained in:
commit
3eb49a813e
3 changed files with 89 additions and 16 deletions
|
@ -1,11 +1,13 @@
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#define MULTIPLEX_PINA D5
|
// WAS D5 D6 D7
|
||||||
#define MULTIPLEX_PINB D6
|
#define MULTIPLEX_PINA 17
|
||||||
#define MULTIPLEX_PINC D7
|
#define MULTIPLEX_PINB 16
|
||||||
|
#define MULTIPLEX_PINC 4
|
||||||
|
|
||||||
#define ANALOG_PIN A0
|
// WAS A0
|
||||||
|
#define ANALOG_PIN 34
|
||||||
|
|
||||||
/*
|
/*
|
||||||
000 0
|
000 0
|
||||||
|
@ -27,8 +29,6 @@
|
||||||
// Ref https://stackoverflow.com/a/523737/1460422
|
// Ref https://stackoverflow.com/a/523737/1460422
|
||||||
#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
|
#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
|
||||||
|
|
||||||
int soilPin = D3;
|
|
||||||
|
|
||||||
float referenceVoltage = 3.3;
|
float referenceVoltage = 3.3;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,21 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
// #include <ArduinoJson.h>
|
// #include <ArduinoJson.h>
|
||||||
#include <ESP8266WiFi.h>
|
|
||||||
|
#include <WiFi.h>
|
||||||
|
|
||||||
|
#ifdef WIFI_ENTERPRISE_ENABLED
|
||||||
|
// Ref https://github.com/martinius96/ESP32-WPA2-enterprise/blob/master/ESP32_WPA2enterprise.ino
|
||||||
|
#include "esp_wpa2.h"
|
||||||
|
#include "esp_wifi.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef MQTT_NO_TLS
|
||||||
|
#include <WiFiClient.h>
|
||||||
|
#else
|
||||||
|
#include <WiFiClientSecure.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "./lib/pubsubclient/PubSubClient.h"
|
#include "./lib/pubsubclient/PubSubClient.h"
|
||||||
#include "./lib/pubsubclient/PubSubClient.cpp"
|
#include "./lib/pubsubclient/PubSubClient.cpp"
|
||||||
|
@ -13,11 +27,14 @@
|
||||||
|
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
#define MULTIPLEX_PINA D5
|
// WAS D5 D6 D7
|
||||||
#define MULTIPLEX_PINB D6
|
|
||||||
#define MULTIPLEX_PINC D7
|
|
||||||
|
|
||||||
#define ANALOG_PIN A0
|
#define MULTIPLEX_PINA 17
|
||||||
|
#define MULTIPLEX_PINB 16
|
||||||
|
#define MULTIPLEX_PINC 4
|
||||||
|
|
||||||
|
// WAS A0
|
||||||
|
#define ANALOG_PIN 34
|
||||||
|
|
||||||
/*
|
/*
|
||||||
000 0
|
000 0
|
||||||
|
@ -40,11 +57,42 @@
|
||||||
// Ref https://stackoverflow.com/a/523737/1460422
|
// Ref https://stackoverflow.com/a/523737/1460422
|
||||||
#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
|
#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
|
||||||
|
|
||||||
|
#ifndef MQTT_NO_TLS
|
||||||
WiFiClientSecure transport;
|
WiFiClientSecure transport;
|
||||||
|
#else
|
||||||
|
WiFiClient transport;
|
||||||
|
#endif
|
||||||
PubSubClient mqtt;
|
PubSubClient mqtt;
|
||||||
|
|
||||||
Adafruit_BME280 bme; // I2C
|
Adafruit_BME280 bme; // I2C
|
||||||
|
|
||||||
|
void connect_wifi() {
|
||||||
|
#ifndef WIFI_ENTERPRISE_ENABLED
|
||||||
|
Serial.print("personal");
|
||||||
|
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
||||||
|
#else
|
||||||
|
Serial.print("enterprise");
|
||||||
|
|
||||||
|
// Ref https://github.com/martinius96/ESP32-WPA2-enterprise/blob/master/ESP32_WPA2enterprise.ino
|
||||||
|
// For ESP32 ONLY! For esp8266, see the code with the esp8266-last tag, which is the last commit that supports the esp8266.
|
||||||
|
WiFi.disconnect(true);
|
||||||
|
WiFi.mode(WIFI_STA);
|
||||||
|
|
||||||
|
const char* user = WIFI_ENTERPRISE_USERNAME;
|
||||||
|
const char* pass = WIFI_ENTERPRISE_PASSWORD;
|
||||||
|
|
||||||
|
// 'esp_wifi_sta_wpa2_ent_set_identity' was not declared in this scope :-(
|
||||||
|
esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)user, strlen(user));
|
||||||
|
esp_wifi_sta_wpa2_ent_set_username((uint8_t *)user, strlen(user));
|
||||||
|
esp_wifi_sta_wpa2_ent_set_password((uint8_t *)pass, strlen(pass));
|
||||||
|
esp_wpa2_config_t config = WPA2_CONFIG_INIT_DEFAULT();
|
||||||
|
esp_wifi_sta_wpa2_ent_enable(&config);
|
||||||
|
|
||||||
|
WiFi.begin(WIFI_SSID);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
float read_analog(int channel) {
|
float read_analog(int channel) {
|
||||||
|
|
||||||
const char* bin = std::bitset<8>(channel).to_string().c_str();
|
const char* bin = std::bitset<8>(channel).to_string().c_str();
|
||||||
|
@ -96,7 +144,8 @@ void setup() {
|
||||||
// https://gist.github.com/Matheus-Garbelini/2cd780aed2eddbe17eb4adb5eca42bd6
|
// https://gist.github.com/Matheus-Garbelini/2cd780aed2eddbe17eb4adb5eca42bd6
|
||||||
// TODO Add support for enterprise WiFi here so we can connect to eduroam
|
// TODO Add support for enterprise WiFi here so we can connect to eduroam
|
||||||
Serial.print("WIFI: ");
|
Serial.print("WIFI: ");
|
||||||
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
|
||||||
|
connect_wifi();
|
||||||
|
|
||||||
int attempts = 0;
|
int attempts = 0;
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
|
@ -117,11 +166,22 @@ void setup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.print("MQTT: ");
|
Serial.print("MQTT: ");
|
||||||
|
#ifdef MQTT_NO_TLS
|
||||||
|
Serial.print("notls");
|
||||||
|
#else
|
||||||
|
Serial.print("tls");
|
||||||
transport.setInsecure(); Serial.print(".");
|
transport.setInsecure(); Serial.print(".");
|
||||||
|
#endif
|
||||||
|
// mqtt.setBufferSize(1000);
|
||||||
mqtt.setClient(transport); Serial.print(".");
|
mqtt.setClient(transport); Serial.print(".");
|
||||||
mqtt.setServer(MQTT_SERVER, MQTT_PORT); Serial.print(".");
|
mqtt.setServer(MQTT_SERVER, MQTT_PORT); Serial.print(".");
|
||||||
|
// Serial.print(MQTT_SERVER);
|
||||||
|
// Serial.print(":");
|
||||||
|
// Serial.print(MQTT_PORT);
|
||||||
|
// Serial.print(".");
|
||||||
|
|
||||||
if(!mqtt.connect(
|
if(!mqtt.connect(
|
||||||
("autoplant" + String(random(0, 999999))).c_str(),
|
("autoplant_" + String(random(0, 999999))).c_str(),
|
||||||
MQTT_USERNAME, MQTT_PASSWORD)
|
MQTT_USERNAME, MQTT_PASSWORD)
|
||||||
) {
|
) {
|
||||||
/* Ref https://pubsubclient.knolleary.net/api#state
|
/* Ref https://pubsubclient.knolleary.net/api#state
|
||||||
|
|
|
@ -1,13 +1,26 @@
|
||||||
|
// The SSID to connect to
|
||||||
#define WIFI_SSID "CHANGE_ME"
|
#define WIFI_SSID "CHANGE_ME"
|
||||||
|
// The password to use to connect
|
||||||
#define WIFI_PASSWORD "CHANGE_ME"
|
#define WIFI_PASSWORD "CHANGE_ME"
|
||||||
|
|
||||||
|
// Enterprise authentication. Uncomment to enable.
|
||||||
|
// #define WIFI_ENTERPRISE_ENABLED
|
||||||
|
// #define WIFI_ENTERPRISE_USERNAME "CHANGE_ME"
|
||||||
|
// #define WIFI_ENTERPRISE_PASSWORD "CHANGE_ME"
|
||||||
|
|
||||||
|
// The domain/IP of the MQTTS server
|
||||||
#define MQTT_SERVER "mqtt.example.com"
|
#define MQTT_SERVER "mqtt.example.com"
|
||||||
|
// The port to connect to.
|
||||||
// 1883 = unencrypted, 8883 = encrypted
|
// 1883 = unencrypted, 8883 = encrypted
|
||||||
// Connections are encrypted by default. There isn't currently a way to disable it.
|
// Connections are encrypted by default. There isn't currently a way to disable it.
|
||||||
#define MQTT_PORT "8883"
|
#define MQTT_PORT 8883
|
||||||
|
// The username to authenticate with when connecting to the MQTT server.
|
||||||
#define MQTT_USERNAME "autoplant"
|
#define MQTT_USERNAME "autoplant"
|
||||||
|
// The password to authenticate with when connecting to the MQTT server.
|
||||||
#define MQTT_PASSWORD "CHANGE_ME"
|
#define MQTT_PASSWORD "CHANGE_ME"
|
||||||
|
// Uncomment to disable TLS. NOT RECOMMENED. USE TLS WHEREVER POSSIBLE.
|
||||||
|
// PASSWORDS ARE SENT IN PLAIN TEXT WHEN YOUDO NOT USE TLS!!!!!!
|
||||||
|
//#define MQTT_NO_TLS
|
||||||
|
|
||||||
|
// The interval at which messages should be sent to the MQTT server, in seconds
|
||||||
|
|
||||||
#define INTERVAL 5*60*1000
|
#define INTERVAL 5*60*1000
|
||||||
|
|
Loading…
Reference in a new issue