Mobile Power activator is a module that can be controlled remotelly using sms text messages activating or deactivating 220V power plugs. It is also able to locate the module using a GPS card and store gps coordinates on a cloud based platform.
If you need additional specific information about this topic or if you want to look it personally please write an email
Adafruit Fona is an interesting controller that can be used as GSM/GPRS module and contemporary has a GPS module on board. It is very easy to drive also because Adafruit has built a simple library to use it.
Once all components have been decided we can just draw a quick schema to let you understand how it could work.
In few words, power IN is 220V and is a tension coming from an alternate power source (any domestic plug). The phase 1 is in common with all plugs. Each phase 2 pole is connected to each relays and from there to each phase 2 connectors of each output plug. The relays card is then connected to Arduino UNO together with the Adafruit Fona using all available digital PINs.
#define FONA_RX 3 //connect to FONA RX
#define FONA_TX 4 //connect to FONA TX
#define FONA_KEY 6 //connection to FONA KEY
#define FONA_PS 7 //connect to FONA PS
#define FONA_RST 2 //Connect to the FONA RST field
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;
Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
Now, Activate the Fona and the GPRS channel (NOTE: I used my local provider APN but you need validate your:
fonaSerial->begin(4800);
if (!fona.begin(*fonaSerial)) {
Serial.println(F("Couldn't find FONA"));
while (1);
}
fona.setGPRSNetworkSettings(F("wap.omnitel.it"), F(""), F(""));
//Init GPRS
if (!fona.enableGPRS(true)) {
Serial.println(F("ERROR:Failed to turn on GPRS 1st Attempt"));
delay(1000);
fona.enableGPRS(false);
delay(1000);
if (!fona.enableGPRS(true)) {
Serial.println(F("ERROR:Failed to turn on GPRS 2nd Attempt"));
return;
}
//continue
}
This is where you need to read SMS messages coming to Fona sim card
if (!fona.readSMS(1, replybuffer, 250, &smslen)) { // pass in buffer and max len!
Serial.println("Failed!");
break;
}
else
{
//Verify if the SMS received is a command SMS and is a Relay Control Command
if (strncmp(replybuffer, "relay", 5) == 0)
RelayNumber = atoi((const char*)replybuffer[5]);
if (replybuffer[7] == '1')
digitalWrite(RelayPin[RelayNumber], LOW);
else
digitalWrite(RelayPin[RelayNumber], HIGH);
}
As you can see from the code I try to read the SMS buffer. If there is nothing then the code go ahead and process another wait cicle. Otherwise the code cheks if the coomand message is a "Relay" message. In case it turns on and off the right Relay switch using the following easy code.
digitalWrite(RelayPin[RelayNumber], LOW);
else
digitalWrite(RelayPin[RelayNumber], HIGH);
The relay is nothing more that a digital pin so when you put it to high you close the switch and the current flow is activated. Otherwise it is closed.
boolean getLocation() {
float latitude, longitude, speed_kph, heading, speed_mph, altitude;
uint8_t GPSReturn;
uint16_t GSMReturn;
char gpsdata[80],tmpGpsdata[80];
int commaCounter, commaLoc[10], commaFound;
char tmpDate[23];
int stat; //GPS fix status
int retry = 0;
float GSMlat, GSMlon;
//get the fix status of the GPS (otherwise has no sense to query
stat = fona.GPSstatus();
if (stat <= 0) {
Serial.println(F("GPS is off exiting"));
return 0;
}
//Get date and Time
fona.getTime(tmpDate, 23);
strncpy(Time, strchr(tmpDate, ',') + 1, 8);
strncpy(Date, tmpDate + 1, 8);
//waiting for the GPS to became available
while ((stat == 1) && (retry=GPSFIXRETRY-1)) {
delay(2000);
stat = fona.GPSstatus();
Serial.println(F("No Fix GPS. Waiting for coordinates"));
retry++;
}
if (retry == GPSFIXRETRY) { //maximum number of retry without signal. Try GSM network
if (!fona.getGSMLoc(&GSMReturn, tmpGpsdata, 80)) {
Serial.println(F("Failed!"));
return 0;
}
//add the 0, at the beginning
sprintf(gpsdata, "0,%s", tmpGpsdata);
}
else
{
//this happens only if GPS signal is ok. Get GPS info
GPSReturn = fona.getGPS(0, gpsdata, 80);
}
//Reply in format: mode,longitude,latitude,altitude,utctime(yyyymmddHHMMSS),ttff,satellites,speed,course
Serial.print("gpsdata: ");
Serial.println(gpsdata);
//if one of the methos is ok
if ((GPSReturn>0) || (GSMReturn>0)) {
//Serach for all the commas into the string received from GPS
commaFound = 0;
for (commaCounter = 0; commaCounter < strlen(gpsdata); commaCounter++) {
if (gpsdata[commaCounter] == ',') {
commaLoc[commaFound] = commaCounter;
commaFound++;
}
}
//strncat the longitude
strncpy(Lon, gpsdata + (commaLoc[GPS_STR_MODE] + 1), commaLoc[GPS_STR_LONGITUDE] - commaLoc[GPS_STR_MODE] - 1);
strncpy(Lat, gpsdata + (commaLoc[GPS_STR_LONGITUDE] + 1), commaLoc[GPS_STR_LATITUDE] - commaLoc[GPS_STR_LONGITUDE] - 1);
Serial.println(F("Reading GPS DATA."));
Serial.print("Values:");
Serial.print(Lon);
Serial.print("-");
Serial.print(Lat);
Serial.print("-");
Serial.print(Date);
Serial.print("-");
Serial.println(Time);
}
else {
Serial.print("ERROR Retrieving GPS info ");
return 0;
}
return 1;
}
And to write the REST function I wrote the following one (Use your REST link where I put the sentence)
void makeRequest() { //Make HTTP GET request and then close out GPRS connection
// read website URL
uint16_t statuscode;
int16_t length;
char url[150];
//Flush the serial
flushSerial();
sprintf(url, "Insert your REST url here with your %s", urlParameter);
//Send the GET request and store the data on the external database
if (!fona.HTTP_GET_start(url, &statuscode, (uint16_t *)&length)) {
Serial.println("Failed!");
return;
}
while (length > 0) {
while (fona.available()) {
char c = fona.read();
// Serial.write is too slow, we'll write directly to Serial register!
#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
loop_until_bit_is_set(UCSR0A, UDRE0); /* Wait until data register empty. */
UDR0 = c;
#else
Serial.write(c);
#endif
length--;
if (!length) break;
}
}
Serial.println(F("\n****"));
fona.HTTP_GET_end();
//CLose the GPRS
Serial.print("Disengage GPRS: ");
if (!fona.enableGPRS(false))
Serial.println(F("Failed to turn off"));
}
In this page, I will show you how to build a REST service. There are many tutorials available on internet. However, I will prepare in the near future a tutorial for this as well.
Have fun with Power Controller ... Considering also that ... I never bought a camper :-)