Hello All, I would like some assistance please with generating a unique/random number in a text message which is sent as an alarm
my current code looks like this
#include <MKRGSM.h> // Include the GSM library
#include "arduino_secrets.h" // Please enter your sensitive data in the Secret tab or arduino_secrets.h
#include<UltraDistSensor.h>
const char PINNUMBER[] = SECRET_PINNUMBER;// PIN Number
GSM gsmAccess;// initialize the library instance
GSM_SMS sms;
UltraDistSensor mysensor;
float reading;
void setup() {
Serial.begin(9600);// initialize serial communications and wait for port to open:
mysensor.attach(12,13);//Trigger pin , Echo pin
Serial.println("SMS Messages Sender");
bool connected = false;// connection state
while (!connected) {
if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
connected = true;
} else {
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("GSM initialized");
sms.beginSMS("+31**********");//enter your number here
sms.print("Alarm Has Restarted Following A Power Outage");//this sends an SMS once only on powerup
sms.endSMS();
Serial.println("SMS Sent");
delay(1000);
sms.beginSMS("+31-------------");//enter a 2nd number here is required
sms.print("Alarm Has Restarted Following A Power Outage");//this sends an SMS once only on powerup
sms.endSMS();
Serial.println("SMS Sent");
delay(1000);
}
void loop() {
reading=mysensor.distanceInCm();
Serial.print("Sensor Reading :");Serial.print(reading);Serial.println(" CM");//measuring distances every 3seconds (3* delays of 1000ms)
delay(1000);
if(reading < 117)//read the distance in the serial monitor of the area you want to cover, in this case <117 is any object moves within 117cm send the alerts
{
sms.beginSMS("+31***********");//enter your number here
sms.print("Proximity Alert");//alarm to be sent
sms.endSMS();
Serial.println("SMS Sent");
delay(1000);
sms.beginSMS("+31-------------");//enter a 2nd number here is required
sms.print("Proximity Alert");//alarm to be sent
sms.endSMS();
Serial.println("SMS Sent");
delay(60000); //delay 15min, no measurements made or alerts sent during this period
}else{
delay (1000);
}
}
this alarm uses an ultrasonic sensor and works perfectly but I have found I may be getting duplicate SM's some with significant delays so I need a reference number to rule that out
so if I create a random number with this
randomSeed(analogRead(0));
}
void loop() {
// print a random number from 0 to 299
randNumber = random(300);
Serial.println(randNumber);
// print a random number from 10 to 19
randNumber = random(10, 20);
Serial.println(randNumber);
delay(50);
}
can you please advise how to incorporate that into the SMS, is it something like this?
sms.beginSMS("+31**********");//enter your number here
sms.print("Alarm Has Restarted Following A Power Outage", randNumber);//this sends an SMS once only on powerup
sms.endSMS();
Serial.println("SMS Sent");
delay(1000);
thank you for taking time to respond
Dan