-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4bed8f4
Showing
11 changed files
with
848 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#include "uBlox.h" | ||
#include <SoftwareSerial.h> | ||
|
||
//Simple sketch to start a connection as client. | ||
/* | ||
GSM board power test | ||
D2 : reset sense | ||
D3 : MSIO | ||
D4 : MOSI | ||
D5 : GSM powerup signal | ||
D6 : GSM reset signal | ||
D7 : GSM PSU control | ||
*/ | ||
char msg[50]; | ||
int numdata; | ||
char inSerial[50]; | ||
char ip[15]; | ||
int i=0; | ||
int socket; | ||
boolean started=false; | ||
|
||
void setup() | ||
{ | ||
//Serial connection. | ||
Serial.begin(9600); | ||
Serial.println("GSM Shield testing."); | ||
//Start configuration of shield with baudrate. | ||
//For http uses is raccomanded to use 4800 or slower. | ||
if (gsm.begin(9600)) | ||
{ | ||
Serial.println("\nstatus=READY"); | ||
started=true; | ||
} | ||
else Serial.println("\nstatus=IDLE"); | ||
|
||
if(started){ | ||
//GPRS attach, put in order APN, username and password. | ||
//If no needed auth let them blank. | ||
if (gsm.attachGPRS(0,"internet", "guest", "guest")) | ||
{ | ||
Serial.println("status=ATTACHED"); | ||
delay(1000); | ||
//Read IP address. | ||
gsm.ip(ip); | ||
delay(100); | ||
Serial.println(ip); | ||
Serial.println(gsm.signal(0)); | ||
if(gsm.connectTCP("echo.u-blox.com",7,socket)) | ||
{ | ||
delay(2000); | ||
gsm.WhileSimpleRead(); | ||
delay(1000); | ||
gsm.disconnectTCP(socket); | ||
} | ||
} | ||
else Serial.println("status=ERROR"); | ||
} | ||
} | ||
|
||
void loop() | ||
{ | ||
//Read for new byte on serial hardware, | ||
//and write them on NewSoftSerial. | ||
serialhwread(); | ||
//Read for new byte on NewSoftSerial. | ||
serialswread(); | ||
} | ||
|
||
void serialhwread(){ | ||
i=0; | ||
if (Serial.available() > 0){ | ||
while (Serial.available() > 0) { | ||
inSerial[i]=(Serial.read()); | ||
delay(10); | ||
i++; | ||
} | ||
|
||
inSerial[i]='\0'; | ||
if(!strcmp(inSerial,"/END")){ | ||
pinMode(6,OUTPUT); | ||
digitalWrite(6,LOW); | ||
delay(200); | ||
pinMode(6,INPUT); | ||
|
||
gsm.SimpleWriteln("AT+CPWROFF"); | ||
} | ||
//Send a saved AT command using serial port. | ||
if(!strcmp(inSerial,"TEST")){ | ||
Serial.println("SIGNAL QUALITY"); | ||
gsm.SimpleWriteln("AT+CSQ"); | ||
} | ||
|
||
//Read last message saved. | ||
if(!strcmp(inSerial,"MSG")){ | ||
Serial.println(msg); | ||
} | ||
else{ | ||
Serial.println(inSerial); | ||
gsm.SimpleWriteln(inSerial); | ||
} | ||
inSerial[0]='\0'; | ||
} | ||
} | ||
|
||
void serialswread(){ | ||
gsm.SimpleRead(); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include <SoftwareSerial.h> | ||
|
||
/* | ||
GSM board power test | ||
D2 : reset sense | ||
D3 : MSIO | ||
D4 : MOSI | ||
D5 : GSM powerup signal | ||
D6 : GSM reset signal | ||
D7 : GSM PSU control | ||
*/ | ||
//SoftwareSerial uBlox(10,9); | ||
|
||
#define power_ctrl 15 // 15 // 5 | ||
#define reset_ctrl 16 // 16 | ||
|
||
void setup() { | ||
// initialize the digital pin as an output. | ||
// Pin 13 has an LED connected on most Arduino boards: | ||
pinMode(power_ctrl, OUTPUT); //GSM module control power_ctrl | ||
pinMode(reset_ctrl, OUTPUT); //GSM module reset control reset_ctrl | ||
pinMode(13, OUTPUT); //onboard LED | ||
digitalWrite(power_ctrl , HIGH); //GSM module OFF | ||
digitalWrite(reset_ctrl , HIGH); //GSM module reset control | ||
|
||
digitalWrite(reset_ctrl , HIGH); //GSM module reset control | ||
delay(100); | ||
digitalWrite(reset_ctrl , LOW); //GSM module reset OFF | ||
|
||
delay(100); | ||
|
||
digitalWrite(power_ctrl , HIGH); //startup sequence | ||
delay(30); // 30 ms delay for start pulse | ||
digitalWrite(power_ctrl , LOW); //startup sequence end | ||
|
||
/* | ||
digitalWrite(power_ctrl , LOW); //startup sequence | ||
delay(30); // 30 ms delay for start pulse | ||
pinMode(power_ctrl, INPUT); //GSM module control power_ctrl | ||
// Serial.println("Module started, wait 2 s for interfaces to configure "); | ||
*/ | ||
digitalWrite(13,HIGH); // turn LED on | ||
// delay(1000); | ||
//uBlox.write("AT\n"); | ||
} | ||
|
||
void loop() | ||
{ | ||
/* | ||
if (uBlox.available()) | ||
Serial.write(uBlox.read()); | ||
if (Serial.available()) | ||
uBlox.write(Serial.read()); | ||
*/ | ||
} | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
#include <PMStreaming.h> | ||
#include <PowerMonitor.h> | ||
#include <SoftwareSerial.h> | ||
#include <uBlox.h> | ||
#include <TextFinder.h> | ||
|
||
#define INTERVAL 1000 // update interval in milliseconds | ||
#define smillis() ((long)millis()) // This is used to calculate timeouts | ||
long updatetime; // used to store the time till next upodate | ||
|
||
long resettime; // used to store the time till next upodate | ||
#define RESETINTERVAL 2700000 // re register modem every 45 minutes(27) // 36 for 1 hour | ||
PowerMonitor pmon; // instance of a powermonitor | ||
|
||
|
||
int socket; //create a socket to work in // this will be changed to an available socket inside the gsm library | ||
boolean update_now= false; | ||
int message_length; // used to hold the message lentgh | ||
int turnedOn =0; | ||
|
||
#define ledpin 13 | ||
int sample =0; | ||
int time = 30; | ||
|
||
void setup() | ||
{ | ||
pinMode(ledpin,OUTPUT); | ||
digitalWrite(ledpin,HIGH); | ||
// Serial.begin(9600); | ||
pmon.begin(220,50); | ||
gsm.begin(9600); // u-blox gsm on here. | ||
digitalWrite(ledpin,LOW); | ||
updatetime= smillis(); // immediatly update after startup | ||
resettime= smillis() +RESETINTERVAL; | ||
//update_now = true; // we have waited long enough, lets update | ||
// delay(1); | ||
} | ||
|
||
void loop() // run over and over | ||
{ | ||
|
||
if(after(resettime)) // // re register with network every hour to keep gprs profile hihj enough proirotuy on th network | ||
{ | ||
// Serial << "Modem Re-Register"<<endl; | ||
gsm.poweroff(); | ||
gsm.begin(9600); | ||
pmon.begin(220,50); | ||
delay(20000); | ||
updatetime= smillis()+INTERVAL; // "reset" the timer to update again in the next interval | ||
resettime= smillis()+RESETINTERVAL; // re register with network agin in 1 hour | ||
} | ||
|
||
if(after(updatetime)) // 1 second has elapsed | ||
{ | ||
digitalWrite(ledpin,HIGH); | ||
sample++; | ||
// Serial<<time-sample<<" "; | ||
if (sample>=time) | ||
{ | ||
sample =0; // resets the counter | ||
update_now = true; // we have waited long enough, lets update | ||
} | ||
delay(50); // waist some time | ||
/* | ||
double temp; | ||
temp= pmon.powerFactor(1); | ||
temp= pmon.Temperature(1); | ||
temp= pmon.lineFrequency(1); | ||
temp= pmon.power(1); | ||
temp= pmon.vrms(1); | ||
*/ | ||
updatetime= smillis()+INTERVAL; // "reset" the timer to update again in the next interval | ||
digitalWrite(ledpin,LOW); | ||
}//updatetime if | ||
|
||
if(update_now) //time to send things to server | ||
{ | ||
update_now=false; // reset our update indicator | ||
|
||
// Serial<<endl; | ||
// send the update string | ||
String myDataString = ""; //allocate for actual data sent | ||
myDataString += "pfac"; | ||
myDataString += "="; | ||
myDataString += String(pmon.powerFactor(1)); | ||
myDataString += "&temp"; | ||
myDataString += "="; | ||
myDataString += String(pmon.Temperature(1)); | ||
myDataString += "&freq"; | ||
myDataString += "="; | ||
myDataString += String(pmon.lineFrequency(1)); | ||
myDataString += "&power"; | ||
myDataString += "="; | ||
myDataString += String(pmon.power(1)); | ||
myDataString += "&vrms"; | ||
myDataString += "="; | ||
myDataString += String(pmon.vrms(1)); | ||
|
||
if (gsm.attachGPRS(0,"internet", "guest", "guest")) | ||
{ | ||
// Serial<<"Signal: " <<gsm.signal(0)<<"/31"<<endl; | ||
digitalWrite(ledpin,HIGH); | ||
if(gsm.connectTCP("m2.exosite.com",80,socket)) | ||
{ // we have an open tunnel to the server... stream some data | ||
|
||
gsm.SimpleWrite(F("POST /api:v1/stack/alias HTTP/1.1\r\n")); | ||
gsm.SimpleWrite(F("Host: m2.exosite.com\r\n")); | ||
gsm.SimpleWrite(F("X-Exosite-CIK: ")); | ||
gsm.SimpleWrite(F("a4426624b5071da75bcab201c2fb27597ed7af95")); // key goes here | ||
gsm.SimpleWrite(F("\r\nContent-Type: application/x-www-form-urlencoded; charset=utf-8\r\n")); | ||
gsm.SimpleWrite(F("Accept: application/xhtml+xml\r\n")); | ||
gsm.SimpleWrite(F("Content-Length: ")); | ||
gsm.SimpleWrite( myDataString.length()); | ||
gsm.SimpleWrite(F("\r\n\r\n")); | ||
gsm.SimpleWrite(myDataString); | ||
gsm.SimpleWrite(F("\r\n")); | ||
delay(200); | ||
// gsm.SimpleRead(); | ||
|
||
// Serial << myDataString << endl << "datalength: "<< myDataString.length()<<endl; | ||
// delay(200); | ||
gsm.disconnectTCP(socket); //disconnect after sending | ||
|
||
}//tcp if | ||
}//gprs attach if | ||
digitalWrite(ledpin,LOW); | ||
|
||
}//update if | ||
delay(100); // waste some time | ||
|
||
}// loop | ||
|
||
|
||
boolean after(long timeout) // Returns true if a timeout has happened | ||
{ | ||
return smillis()-timeout>0; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include <SoftwareSerial.h> | ||
|
||
#include <TextFinder.h> | ||
#include <PowerMonitor.h> | ||
#include <Streaming.h> | ||
|
||
|
||
SoftwareSerial xbee(2,3); | ||
PowerMonitor pmon; | ||
#define INTERVAL 2000 | ||
#define smillis() ((long)millis()) // This is used to calculate timeouts | ||
long updatetime; | ||
|
||
double readings[] = {0.00,0.00,0.00,0.00}; // Vrms, RealPower,aqumilated energy, Temperature | ||
void setup() | ||
{ | ||
xbee.begin(38400); | ||
pmon.begin(220,50); // 220V and 50Hz are nominal parameters for south africa | ||
updatetime= smillis(); | ||
} | ||
|
||
void loop() // run over and over | ||
{ | ||
|
||
//delay(1000); | ||
if(after(updatetime)) | ||
{ | ||
readings[0] = pmon.vrms(1); | ||
delay(20); | ||
readings[1] = pmon.power(1); | ||
delay(20); | ||
readings[2] = pmon.energy(1); | ||
delay(20); | ||
readings[3] = pmon.Temperature(1); | ||
delay(20); | ||
xbee << "Vrms : \t\t"<< readings[0] <<endl<< "Real power : \t"<< readings[1] <<endl<< "Energy : \t\t"<< readings[2] <<endl<< "Temp : \t\t"<< readings[3] <<endl; | ||
updatetime= smillis()+INTERVAL; | ||
} | ||
} | ||
|
||
boolean after(long timeout) // Returns 1 if a timeout occured, otherwise 0. | ||
{ | ||
return smillis()-timeout>0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
Oops, something went wrong.