Skip to content

Instantly share code, notes, and snippets.

@chicks
Last active October 15, 2022 23:07
Show Gist options
  • Save chicks/697f89775d2a808077fc1d8f8e6f6321 to your computer and use it in GitHub Desktop.
Save chicks/697f89775d2a808077fc1d8f8e6f6321 to your computer and use it in GitHub Desktop.
jackcaddy_lilygo_wifi
(base) chicks@Charless-MacBook-Pro jackcaddy % git show a9c172c505341b7c1d7e87a7de833e14cab89e7e
commit a9c172c505341b7c1d7e87a7de833e14cab89e7e (HEAD -> lte_refactor_broken)
Author: Charles Hicks <charles@longtail.energy>
Date: Sat Oct 15 16:02:45 2022 -0700
Attempt to refactor for lte support.
diff --git a/platformio.ini b/platformio.ini
index 26a0870..13d0e63 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -15,10 +15,11 @@ framework = arduino
lib_deps =
siruli/MAX6675 @ ^2.1.0
roboticsbrno/ServoESP32 @ ^1.0.3
- nkolban/ESP32 BLE Arduino@^1.0.1
+;nkolban/ESP32 BLE Arduino
adafruit/Adafruit MPU6050 @ ^2.2.2
knolleary/PubSubClient@^2.8
bblanchon/ArduinoJson@^6.19.4
vshymanskyy/TinyGSM@^0.11.5
build_type = debug
+upload_port = /dev/cu.wchusbserial54250286621
monitor_filters = esp32_exception_decoder
diff --git a/src/config.h b/src/config.h
index 4114289..404223f 100644
--- a/src/config.h
+++ b/src/config.h
@@ -11,6 +11,8 @@ namespace longtail
public:
Config();
+ bool useWifi = false;
+ std::string apn;
std::string networkSsid;
std::string networkPassword;
@@ -26,14 +28,16 @@ namespace longtail
// TODO: Get these from local environment during dev or build flags
Config::Config(void)
{
- networkSsid = "Smada24";
- networkPassword = "";
+ useWifi = false;
+ apn = "hologram";
+ networkSsid = "c-licious-24g";
+ networkPassword = "c-licious";
// TODO: Use the ESP lib to get something useful here
mqttClientId = WiFi.macAddress().c_str();
mqttBrokerHost = "mqtt.longtail.energy";
mqttBrokerPort = 8883;
mqttUsername = "longtail";
- mqttPassword = "";
+ mqttPassword = "Longtail123!";
// TODO: Is this the right way to do this?
if (mqttClientId.length() > 0)
diff --git a/src/dev/temperature.h b/src/dev/temperature.h
new file mode 100644
index 0000000..e69de29
diff --git a/src/io/networking.h b/src/io/networking.h
index a510ca2..7724131 100644
--- a/src/io/networking.h
+++ b/src/io/networking.h
@@ -5,6 +5,26 @@
#include <WiFiClient.h>
#include <WiFiClientSecure.h>
+#define TINY_GSM_MODEM_SIM7000
+
+// Set serial for debug console (to the Serial Monitor, default speed 115200)
+#define SerialMon Serial
+
+#define TINY_GSM_RX_BUFFER 1024 // Set RX buffer to 1Kb
+#define DUMP_AT_COMMANDS
+
+#include <TinyGsmClient.h>
+
+#define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */
+#define TIME_TO_SLEEP 60 /* ESP32 should sleep more seconds (note SIM7000 needs ~20sec to turn off if sleep is activated) */
+RTC_DATA_ATTR int bootCount = 0;
+
+HardwareSerial serialGsm(1);
+#define SerialAT serialGsm
+#define TINY_GSM_USE_GPRS true
+#define TINY_GSM_USE_WIFI false
+
+
#include <config.h>
@@ -14,7 +34,14 @@ namespace longtail
Client * establishNetworking(Config * config)
{
- establishWifi(config);
+ if (config->useWifi)
+ {
+ establishWifi(config);
+ } else
+ {
+ establishCellular(config);
+ }
+
// auto client = new WiFiClient();
auto client = new WiFiClientSecure();
client->setInsecure(); // TODO: Just for now
@@ -77,6 +104,26 @@ namespace longtail
Serial.print("Local ESP32 IP: ");
Serial.println(WiFi.localIP());
}
+
+ void establishCellular(Config * config)
+ {
+ // WiFi.mode(WIFI_MODE_STA);
+ // WiFi.setSleep(WIFI_PS_NONE);
+ Serial.println("\nConnecting");
+ auto status = WiFi.begin(
+ config->networkSsid.c_str(),
+ config->networkPassword.c_str());
+ while (status != WL_CONNECTED)
+ {
+ Serial.println(get_wifi_status(status));
+ delay(1 * 1000);
+ status = WiFi.status();
+ }
+
+ Serial.println("\nConnected to the WiFi network");
+ Serial.print("Local ESP32 IP: ");
+ Serial.println(WiFi.localIP());
+ }
}
#endif
\ No newline at end of file
diff --git a/src/io/temperature.h b/src/io/temperature.h
new file mode 100644
index 0000000..e69de29
diff --git a/src/main.cpp b/src/main.cpp
index 0e83dd8..7650fae 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -31,7 +31,7 @@ void setup()
// Initialize the primary I2C bus
auto wire = new TwoWire(0);
- if (!wire->begin(18, 19, 0U))
+ if (!wire->begin(21, 22, 0U))
{
Serial.println("Failed to initialize the I2C bus.");
exit(-1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment