Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
skullkey committed Apr 3, 2012
0 parents commit 4bed8f4
Show file tree
Hide file tree
Showing 11 changed files with 848 additions and 0 deletions.
110 changes: 110 additions & 0 deletions GSM_GPRSLibrary_Client/GSM_GPRSLibrary_Client.ino
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();
}


62 changes: 62 additions & 0 deletions GSM_power_supply_test/GSM_power_supply_test.ino
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());
*/
}





139 changes: 139 additions & 0 deletions OpenPower_exosite/OpenPower_exosite.ino
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;
}


45 changes: 45 additions & 0 deletions Powermon_library_test/Powermon_library_test.ino
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;
}

1 change: 1 addition & 0 deletions Powermon_library_test/powermon_drivers.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions openpower_GPRS/GPRS.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading

0 comments on commit 4bed8f4

Please sign in to comment.