Sending SMS from Arduino + Wifi Shield


hi there,

i guess found new way try send sms arduino. found http://www.instructables.com/id/send-sms-from-arduino-over-the-internet-using-enc2/?allsteps. stated can change little bit program make work wifi shield seems program not running when uploaded arduino.

here's code:

code: [select]

#include <spi.h>
#include <wifi.h>
#include <wificlient.h>
#include <wifiserver.h>
#include <wifiudp.h>

//thingspeak server
char server[] = "api.thingspeak.com";

char ssid[] = "ssid";     
char pass[] = "pass"; 

wificlient client;

//api key thingspeak thinghttp configured
const string apikey = "api_key";

//the number message should sent to
const string sendnumber = "phone_number";

void setup()
{
  serial.begin(9600);
  setupwifi();
 
  //send sms
  serial.println("sending sms");
 
  //this function send sms
  //the first argument number send to, formatted +12345678901
  //the second argument body of text message, must within urlencode()
  sendsms(sendnumber, urlencode("hello world!"));

}

void loop()
{

}


void sendsms(string number,string message)
{
  // make tcp connection remote host
  if (client.connect(server, 80))
  {

    //should this...
    //api.thingspeak.com/apps/thinghttp/send_request?api_key={api key}&number={send number}&message={text body}
   
    client.print("get /apps/thinghttp/send_request?api_key=");
    client.print(apikey);
    client.print("&number=");
    client.print(number);
    client.print("&message=");
    client.print(message);
    client.println(" http/1.1");
    client.print("host: ");
    client.println(server);
    client.println("connection: close");
    client.println();
   
 
  }
  else
  {
    serial.println(f("connection failed"));
  }

  // check response server, , route it
  // out serial port.
  while (client.connected())
  {
    if ( client.available() )
    {
      char c = client.read();
      serial.print(c);
    }     
  }
  serial.println();
  client.stop();
}


void setupwifi()
{
  serial.println("setting wifi...");
  //start wifi connection
  wifi.begin(ssid, pass);

  serial.print("connected ssid: ");
  serial.println(ssid);
  delay(1000);
}

string urlencode(const char* msg)
{
  const char *hex = "0123456789abcdef";
  string encodedmsg = "";

  while (*msg!='\0'){
    if( ('a' <= *msg && *msg <= 'z')
      || ('a' <= *msg && *msg <= 'z')
      || ('0' <= *msg && *msg <= '9') ) {
      encodedmsg += *msg;
    }
    else {
      encodedmsg += '%';
      encodedmsg += hex[*msg >> 4];
      encodedmsg += hex[*msg & 15];
    }
    msg++;
  }
  return encodedmsg;
}


the message stated on serial monitor is:

setting wifi...

attempting connect wep network, ssid: iotlab

sending sms

h

any idea wrong here? message seem not able through phone. appreciate time in helping. in advance.

hazirah

it usual send blank line here:
code: [select]

    client.print("host: ");
    client.println(server);
    client.println(""); //new


good don't message "connection failed".


Arduino Forum > Using Arduino > Project Guidance > Sending SMS from Arduino + Wifi Shield


arduino

Comments

Popular posts from this blog

DHT11 Time out error using v0.4.1library

Sketch upload fails with Java error (___REMOVE___/bin/avrdude)!

Arduino Uno + KTY81/210 temperature sensor