I'm using an ethernet shield to poll a php page for changes. It works great(ish)!
I also have a SM5100B shield from sparkfun: http://www.sparkfun.com/commerce/product_info.php?products_id=9607. I've gotten it to send and receive texts.
Now, I'd like to get my chocolate in my peanut butter and have them to work together. The Ethernet shield gets an update from the web, the SM5100B sends a text.
I can connect fine to a server through the ethernet shield when I'm not stacking the boards, but as soon as I pop on the GSM shield, the ethernet no longer works, but the modem does. Any ideas why?
Code below (edited to add comments!):
#include <SPI.h>
#include <Ethernet.h>
#include <NewSoftSerial.h> //Include the NewSoftSerial library to send serial commands to the cellular module.
#include <string.h> //Used for string manipulations
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //MAC addresss (self-assigned)
byte ip[] = {
192,168,1,177 }; //my IPaddress
byte server[] = {
173,236,156,236 }; //Who are we talking to?
String content=" "; //to hold stuff from the web, eventually to send out
int stringPos=0; //position in the array for writing web content
char inChar=0; //Will hold the incoming character from the Ethernet Interface
char incoming_char=0; //Will hold the incoming character from the Cell Serial Port
NewSoftSerial cell(2,3); //Create a 'fake' serial port. Pin 2 is the Rx pin, pin 3 is the Tx pin.
// Initialize the Ethernet client library
void setup() {
// start the Ethernet connection:
Ethernet.begin(mac, ip);
// give the Ethernet shield a second to initialize:
delay(1000);
// start the serial library:
Serial.begin(9600);
delay(1000);
cell.begin(9600); //start cell communication
}
void loop()
{
// Initialize the Ethernet client library
Client client =Client(server, 80); //
// Make a HTTP request if connected:
if(client.connect()){
Serial.println("connected");
client.println("GET /sms/out.php HTTP/1.1");
client.println("Host: insight.no.com");
client.println();
}
else{
// kf[sic] you didn't get a connection to the server:
Serial.println("Error connecting");
}
delay(1000);
//this strips out the header information
if (client.available()) {
readAgain:
inChar=client.read();
if(inChar!='`'){
goto readAgain;}
Serial.println("found message start");
}
//refill the buffer...
delay(1000);
//this reads to the end of the 'data'
if (client.available()) {
getMore:
inChar=client.read();
if(inChar!='~'){
content[stringPos]=inChar;
stringPos++;
goto getMore;}
}
//GIVE ME THE MESSAGE
Serial.println(content);
//if we're all done, why not disconnect? Seems like a nice thing to do
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting");
}
//reset the parameters for the web reading
inChar=-1;
content=" ";
client.stop();
stringPos=0;
//while there's stuff in the cell modem buffer
while(cell.available())
{
incoming_char=cell.read(); //Get the character from the cellular serial port.
Serial.print(incoming_char); //Print the incoming character to the terminal.
}
delay(2500);
}