Skip to content

Instantly share code, notes, and snippets.

@WassifAziz
Created July 5, 2012 14:25
Show Gist options
  • Save WassifAziz/3053973 to your computer and use it in GitHub Desktop.
Save WassifAziz/3053973 to your computer and use it in GitHub Desktop.
arduino send text code
/*Kitchen Sink App*/
// libraries
#include <GSM3SMSService.h>
#include <GSM3ShieldV1AccessProvider.h>
#include <GSM3ShieldV1ClientProvider.h>
#include <GSM3ShieldV1SMSProvider.h>
#include <GSM3ShieldV1DataNetworkProvider.h>
#include <GSM3MobileClientService.h>
// initialize the gsm library instance
GSM3ShieldV1AccessProvider gsm; // include a 'true' parameter for debug enabled
GSM3MobileClientService client((bool)true);
GSM3ShieldV1ClientProvider s1client;
GSM3ShieldV1DataNetworkProvider gprs;
GSM3SMSService sms;
GSM3ShieldV1SMSProvider smsp;
// APN data
#define GPRS_APN "mobile.o2.co.uk" // replace your GPRS APN
#define GPRS_LOGIN "web" // replace with your GPRS login
#define GPRS_PASSWORD "web" // replace with your GPRS password
/*counts for preses*/
int hotdrinksCount;
int colddrinksCount;
int snacksCount;
int mealsCount;
int totaltexts;
/*timer*/
int num_secs = 0;
/*where are we going*/
char *url = "www.mirkat.com";
char *path = "/proxy.php";
void setup() {
Serial.begin(9600);
// Start the GSM shield
if(gsm.begin()!=GSM_READY)
{
Serial.println("Error connecting GSM network.");
while(true);
}
Serial.println("GSM initialized");
// attach GPRS
if(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)!=GPRS_READY)
{
Serial.println("Error connecting GPRS network.");
while(true);
}
else
{
Serial.println("GPRS Connected.");
}
}
void loop() {
/*Setup the reads*/
int sensorValue0 = analogRead(A3) * (5.0 / 1023.0);
int sensorValue1 = analogRead(A2) * (5.0 / 1023.0);
int sensorValue2 = analogRead(A1) * (5.0 / 1023.0);
int sensorValue3 = analogRead(A0) * (5.0 / 1023.0);
/*Configure the weights*/
int button_wait = 500;
int sample_rate = 50;
int button_presses_meals = 0;
/*sms destination*/
char remoteNumber[] = "447715202090";
String txtMsg = "helloworld";
if (sensorValue0 == 5)
{
Serial.println("sensor 0");
delay(button_wait);
hotdrinksCount = hotdrinksCount++;
}
if (sensorValue1 == 5)
{
Serial.println("sensor 1");
delay(button_wait);
colddrinksCount = colddrinksCount++;
}
if (sensorValue2 == 5)
{
Serial.println("sensor 2");
delay(button_wait);
snacksCount = snacksCount++;
}
if (sensorValue3 == 5)
{
Serial.println("sensor 3");
delay(button_wait);
mealsCount = mealsCount++;;
}
delay(sample_rate);
num_secs = num_secs + 1;
char buffer [33];
scanf ("%d",&hotdrinksCount);
String a = itoa (hotdrinksCount,buffer,10);
scanf ("%d",&colddrinksCount);
String b = itoa (colddrinksCount,buffer,10);
scanf ("%d",&snacksCount);
String c = itoa (snacksCount,buffer,10);
printf ("decimal: %s\n",buffer);
String d = itoa (mealsCount,buffer,10);
printf ("decimal: %s\n",buffer);
String total_counts=("A" + a + "-" + "A" + b +"-" + "A" + c + "-" + "A" + d);
if (num_secs > 500){ //5000 is equal to 4.20
num_secs = 0;
sms.beginSMS(remoteNumber);
sms.print(total_counts);
colddrinksCount = 0;
hotdrinksCount = 0;
snacksCount = 0;
mealsCount = 0;
sms.endSMS();
totaltexts = totaltexts + 1;
Serial.print("total texts sent ");
Serial.println(totaltexts);
}
// Serial.println(mealsCount);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment