My program is basically to send SMS and keep a log of Date and Time of the sent messages .
This should be done using an external power supply and disconnected from computer.
To achieve that I tried using RTC of the shield to capture the time at sending the message. However, it does not seem to work properly, even when it works the time and date were wrong.
PS: Sending a message program is working fine. here, is the code to send a message:
// Include the GSM library
#include <GSM.h>
#define PINNUMBER ""
// initialize the library instance
GSM gsmAccess;
GSM_SMS sms;
void setup()
{
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.println("SMS Messages Sender");
// connection state
boolean notConnected = true;
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while(notConnected)
{
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
notConnected = false;
else
{
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("GSM initialized");
}
void loop()
{
Serial.print("Enter a mobile number: ");
char remoteNum[20]; // telephone number to send sms
readSerial(remoteNum);
Serial.println(remoteNum);
// sms text
Serial.print("Now, enter SMS content: ");
char txtMsg[200];
readSerial(txtMsg);
Serial.println("SENDING");
Serial.println();
Serial.println("Message:");
Serial.println(txtMsg);
// send the message
sms.beginSMS(remoteNum);
sms.print(txtMsg);
sms.endSMS();
Serial.println("\nCOMPLETE!\n");
}
/*
Read input serial
*/
int readSerial(char result[])
{
int i = 0;
while(1)
{
while (Serial.available() > 0)
{
char inChar = Serial.read();
if (inChar == '\n')
{
result[i] = '\0';
Serial.flush();
return 0;
}
if(inChar!='\r')
{
result[i] = inChar;
i++;
}
}
}
}
EDIT: After I write the reply I take a look to the code and I can't find any reference to the RTC or the "time set". Is the wrong code? Or the program must to guess that it need to set the time with the RTC?
luisilva:
I can't ask the date/time to the network?
I want to set the clock (RTC) on the shield once then the time will be in the RTC using battery.
luisilva:
EDIT: After I write the reply I take a look to the code and I can't find any reference to the RTC or the "time set". Is the wrong code? Or the program must to guess that it need to set the time with the RTC?
NO, this is the correct code but without the RTC. I tried several codes to use RTC but none is working.
algherbal:
I want to read the time and write it in the SMS
I don't if you know or not, but the network do that job for you. The GSM network writes the time and date in the SMS. If is your only goal, you can send one SMS with anything ("hello", for example) and how receives the SMS will be able to see the time/date.
algherbal:
I want to read the time and write it in the SMS
I don’t if you know or not, but the network do that job for you. The GSM network writes the time and date in the SMS. If is your only goal, you can send one SMS with anything (“hello”, for example) and how receives the SMS will be able to see the time/date.
hi,
I want to set the time and date, to display it on the LCD
This is my final codes:
#include <complex.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
// Include the GSM library
#include <GSM.h>
#define PINNUMBER ""
// initialize the library instance
GSM gsmAccess;
GSM_SMS sms;
Complex Phase(-0.5,0.86602540378444); // a=120 deg
int R_Led = 10;
int Y_Led = 11;
int G_Led = 12;
void setup(){
lcd.init();
lcd.backlight();
lcd.print(" SMS Messages");
lcd.setCursor(6, 1);
lcd.print("Sender");
// connection state
boolean notConnected = true;
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while(notConnected)
{
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
notConnected = false;
else
{
lcd.clear();
lcd.print("Not connected");
delay(1000);
}
}
lcd.clear();
lcd.print("GSM initialized");
}
void loop()
{
char remoteNum[20]; // telephone number to send sms
remoteNum = "39794446";
char txtMsg[200];
txtMsg= "Hello World";
sms.beginSMS(remoteNum);
sms.print(txtMsg);
sms.endSMS();
lcd.print("COMPLETE!");
float CT1, CT2, CT3, VT;
CT1= ReadCurrent('A0');
CT2= ReadCurrent('A1');
CT3= ReadCurrent('A2');
Complex CT1x(CT1/ 0.707,0);
CT1x *= Phase;
Complex CT2x(CT2/ 0.707,0);
CT2x *= Phase;
Complex CT3x(CT3/ 0.707,0);
CT3x *= Phase;
Complex S(0,0);
S = CT1x.conjugate() * VT;
S+= CT2x.conjugate() * VT * Phase * Phase;
S+= CT3x.conjugate() * VT * Phase;
Complex S_Rated(1,1); //to be changed
float Mag_S = S.modulus();
float Mag_S_Rated = S_Rated.modulus();
if (Mag_S >= Mag_S_Rated)
{
digitalWrite(R_Led, HIGH);
digitalWrite(Y_Led, LOW);
digitalWrite(G_Led, LOW);
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("Exceed Limits");
}
else if (Mag_S>= (.1 * Mag_S_Rated))
{
digitalWrite(R_Led, LOW);
digitalWrite(Y_Led, HIGH);
digitalWrite(G_Led, LOW);
lcd.clear();
}
else
{
digitalWrite(R_Led, LOW);
digitalWrite(Y_Led, LOW);
digitalWrite(G_Led, HIGH);
lcd.clear();
}
//LCD
lcd.setCursor(0, 1);
lcd.print("Power=");
lcd.setCursor(7, 1);
lcd.print(S);
delay(10000); // update every 10 seconds
}
float ReadCurrent(char P)
{
// read the input on analog pin 0:
int sensorValue = analogRead(P);
// Convert the analog reading (which goes from 0 - 1023) to a current (0.334 - 4.666V):
float current = sensorValue * ((4.666-.334) / 1023.0);
//Applying Ohms low I= V/R , Burden 33 ohm:
current /= 33.0;
//Convert Peak-Peak To Peak:
current /= 2.0;
//Convert Peak To RMS:
current *= 0.707;
// print out the value you read:
return current;
}