Send SMS via Arduino without GSM

2019-08-26 09:30发布

问题:

Is it possible for Arduino to send a message to the internet without using a GSM shield?

I need an Arduino to send a message pressing a push button, which is connected to an Arduino and Ethernet shield, without using a GSM shield.

I need to send a message just by using HTML/PHP API code included in Server via GET/POST. I'm using this code in this code data nicely insert in SQL Database but if successfully insert data send sms via PHP API. But it's not working. Here is my PHP code:

<?php
  $mysqli = new mysqli("localhost", "user", "password","db");
  $tag=$_GET["value"];
  $result = $mysqli->query("INSERT INTO tag_tbl (tag_value, status) VALUES ('".$tag."', 1)");
  if ($result === false) {
    echo "SQL error:".$mysqli->error;
  } else {
    header("location: https://vas.banglalinksgsm.com/sendSMS/sendSMS?msisdn='xxxxx'&message='".$tag."'&userID=xxxxx&passwd=xxxxxx&sender=WSC");
  }
?>

回答1:

I think you want to send a message to a number when a data is inserted to the database. The best way is to use an online message service provider.

I would suggest you clickatell (which provide some few free messages for testing) , later you can buy api if you want it for commercial purpose. First you need to register on their site. Then login to it, there you can take SMS integrations. In that there is option to create new integration. Enter a name, desciption,then choose an Environment and API and then go through features settings etc. Then you can choose phone numbers here you can add the test phones to which the sms will be free of cost. Then at last save integration. After that you will get an API key which you can use for message services.This video could help you set clickatell API.

Now how can you make it send message?.

You can use it inside your PHP code. The following block of code is enough to send message to a mobile number.

code:

{
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_URL, "https://platform.clickatell.com/messages/http/send?apiKey=place_your_api_key_here&to=place_your_number_here&content=%20%09ALERT%09%20%0A%0AYour%20vehicle%20is%20noticed%20crossing%20the%20speed%20limit%0A%0A%0ASpeed%20:%20".$speed."%20KMPH" );
curl_setopt($ch1, CURLOPT_HEADER, 0);

curl_exec($ch1);

curl_close($ch1);
}

You can use it anywhere inside your php code where you want to send message. Edit the apikey and to in the code as per your api key and your test mobile number. Edit the content portion as your requirement.

%20%09ALERT%09%20%0A%0AYour%20vehicle%20is%20noticed%20crossing%20the%20speed%20limit%0A%0A%0ASpeed%20:%20".$speed."%20KMPH

The above shown is my content. It send message as

Your vehicle is noticed crossing the speed limit
speed: 50 KMPH

%20,%09,%0A are various format specifiers to make the message look formatted (Edit them as you wish). .$speed. is used to add the speed, send from arduino to PHP code, in the message send to phone.



回答2:

You are using header("location: xxx"); is usable to redirect to a given url. You can Call sms RestApi in simple PHP function to send sms:

function CURLsendsms($number, $message_body){
 $api_params = $api_element.'?apikey='.$apikey.'&sender='.$sender.'&to='.$mobileno.'&message='.$textmessage;
 $smsGatewayUrl = "http://springedge.com";
 $smsgatewaydata = $smsGatewayUrl.$api_params;
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_POST, false);
 curl_setopt($ch, CURLOPT_URL, smsgatewaydata);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 $output = curl_exec($ch);
 curl_close($ch);
 // Use file get contents when CURL is not installed on server.
 if(!$output){
 $output =  file_get_contents($smsgatewaydata);  
 }
}

Also you can use php class to send sms http://www.phpclasses.org/package/9522-PHP-Send-SMS-messages-with-Spring-Edge-API.html

There are two files in above class:

  • sendsms.php - Class file to call sms gateway restAPI
  • test.php - Example file to test sms function.

This Class is using spring edge sms gateway provider API you can customize RestAPI url and params for any other sms provider according to requirement.



标签: arduino