Replies: 1 comment
-
Hello @Darksplat, This is a really cool example. Regarding the functionality to send SMS, the modem has the functionality to do this without the Sending from the AVR-IoT Cellular Mini is not much more work, and I'm happy to guide you through it should you have any more questions. We have an example to send AT commands to the modem directly here: https://github.com/microchip-pic-avr-solutions/avr-iot-cellular-arduino-library/blob/main/examples/custom_at_commands/custom_at_commands.ino |
Beta Was this translation helpful? Give feedback.
-
Hi I mentioned this on your YouTube video about this nice little device and was wondering about integrating geofencing into your code and sending it via an SMS when it was in or out of that geoloction. Would the code be something like this?
`
#include <Adafruit_GPS.h>
#include <Arduino.h>
#include <http_client.h>
#include <led_ctrl.h>
#include <log.h>
#include <low_power.h>
#include <lte.h>
#include <mcp9808.h>
#include <veml3328.h>
#include <TinyGPS++.h> // Include the TinyGPS++ library for distance calculation
#include <GSM.h> // Include the library for GSM communication
#define GPSSerial Serial2
#define HTTP_DOMAIN ""
#define MAX_GEOFENCES 5
// Define the user's phone number
const char* userPhoneNumber = "xxxxxxxxxxx";
// Define a struct to hold geofence information
struct Geofence {
String name; // Name of the geofence
float latitude;
float longitude;
float radius;
bool inside; // Flag to indicate if device is inside this geofence
};
// Array to hold geofences
Geofence geofences[MAX_GEOFENCES];
// Number of geofences currently defined
int numGeofences = 0;
// Include the TinyGPS++ library for distance calculation
TinyGPSPlus gps;
// Enum for the state of the device
enum class State { NOT_CONNECTED, CONNECTED, CONNECTED_WITH_FIX };
// Global state variable
static State state = State::NOT_CONNECTED;
// Global variables for GPS data
static char latitude[16] = "0";
static char longitude[16] = "0";
static char time[24] = "0";
static float speed = 0.0;
static int quality = 0;
static int numSatellites = 0;
// Flag to indicate whether GPS data has been parsed
static bool has_parsed = false;
// Last time data was sent to server
unsigned long lastDataSentTime = 0;
GSM gsmAccess; // Initialize GSM module
GSM_SMS sms; // Initialize SMS module
// Function prototypes
void initializeGPS();
void initializeHTTP();
void sendData();
void connectToNetwork();
void parseGPSMessages();
void checkGeofences();
void sendSMS(const char* message);
// Function to initialize GPS and HTTP
void setup() {
LedCtrl.begin();
LedCtrl.startupCycle();
}
// Main loop
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - lastDataSentTime >= 15000) {
lastDataSentTime = currentMillis;
parseGPSMessages();
if (state == State::CONNECTED_WITH_FIX && has_parsed) {
sendData();
checkGeofences();
}
}
}
// Function to initialize GPS
void initializeGPS() {
GPSSerial.swap(1);
GPS.begin(9600);
}
// Function to initialize HTTP client
void initializeHTTP() {
if (!HttpClient.configure(HTTP_DOMAIN, 8080, false)) {
Log.info(F("Failed to configure HTTP client"));
} else {
Log.info(F("Configured HTTP"));
}
}
// Function to send data to the server
void sendData() {
char data[120] = "";
speed = gps.speed.kmph();
quality = gps.satellites.isValid() ? gps.satellites.value() : 0;
numSatellites = gps.satellites.isValid() ? gps.satellites.value() : 0;
}
// Function to connect to the network
void connectToNetwork() {
// If we already are connected, don't do anything
if (!Lte.isConnected()) {
while (!Lte.begin()) {}
Log.infof(F("Connected to operator: %s\r\n"),
Lte.getOperator().c_str());
}
}
// Function to parse GPS messages
void parseGPSMessages() {
// Read the incoming messages, needn't do anything with them yet as that is
// taken care of by the newNMEAReceived() function.
if (GPS.available()) {
GPS.read();
}
}
// Function to check if the device is inside a geofence
void checkGeofences() {
for (int i = 0; i < numGeofences; ++i) {
float distance = TinyGPSPlus::distanceBetween(
gps.location.lat(), gps.location.lng(),
geofences[i].latitude, geofences[i].longitude);
}
// Function to send an SMS
void sendSMS(const char* message) {
// Define APN settings
char apn[] = "live.vodafone.com"; // APN provided by Vodafone
char user[] = ""; // Vodafone may not require username
char password[] = ""; // Vodafone may not require password
/*
This Australian/New Zealand table organises the information by country and carrier, listing the corresponding
Access Point Names (APNs). Please note that some carriers may have multiple APNs for
different services (e.g., internet, MMS), and some carriers may have specific requirements
or settings for certain services.
*/
}
`
Please feel free to use this and modify it and use it as an example. Also any feedback would be nice on the code corrections etc as I don't have an actual device to test this against as I don't want to spend the money on something That doesn't suit my needs
Cheers
Jeremy
Beta Was this translation helpful? Give feedback.
All reactions