2017-08-20 191 views
0

Arduino是否有可能在不使用GSM屏蔽的情況下向互聯網發送消息?通過Arduino發送短信沒有GSM

我需要一個Arduino發送消息按下按鈕,它連接到Arduino和以太網盾,而不使用GSM屏蔽。

我需要通過GET/POST使用服務器中包含的HTML/PHP API代碼發送消息。我在這段代碼中使用這段代碼很好地插入到SQL數據庫中,但是如果成功地通過PHP API插入數據發送短信。但它不起作用。這裏是我的PHP代碼:

<?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"); 
    } 
?> 
+0

您可以發送電子郵件。有這樣的圖書館。 –

+0

你的問題有點含糊。當數據插入數據庫時​​,你想發送確認消息給手機號碼,我認爲這是你的目標。 – Billa

回答

0

我想你想發送一個消息到一個數字時,數據插入到數據庫。最好的方法是使用在線消息服務提供商。

我建議你clickatell(它提供一些免費的測試消息),稍後你可以購買API,如果你想它的商業目的。首先你需要註冊他們的site。然後登錄到它,在那裏你可以採取SMS集成。在那裏可以選擇創建新的集成。輸入一個名稱,desciption,然後選擇一個環境和API,然後通過功能設置等,然後你可以選擇電話號碼,在這裏你可以添加測試手機短信將免費的。最後保存整合。之後,您將獲得一個可用於消息服務的API密鑰。此video可幫助您設置clickatell API。

現在你怎麼能讓它發送消息?

你可以在你的PHP代碼中使用它。以下代碼塊足以將消息發送到手機號碼。

代碼:

{ 
$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); 
} 

你可以在任何地方使用它你的PHP代碼中要發送的消息。根據您的api密鑰和您的測試手機號碼,在代碼中編輯apikeyto。按照您的要求編輯內容部分。

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

以上顯示的是我的內容。它發送消息

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

%20%09%0A各種格式說明,以使看起來格式化(編輯它們,你願意的話)的消息。 .$speed.用於在發送到手機的消息中添加從arduino發送到PHP代碼的速度。

+0

這會幫助你解決你的問題。隨意問你是否有任何疑問 – Billa

+0

兄弟你的代碼無法正常工作..請幫助 –

+0

兄弟你的代碼無法正常工作..請幫助。我的API鏈接是https://vas.banglalinksgsm.com/sendSMS/sendSMS?msisdn='xxxxx'&message='".$tag."'&userID=xxxxx&passwd=xxxxxx當我從ardunio標籤插入按鈕velue插入成功,但SMS不發送。當我複製這個API鏈接並粘貼瀏覽器地址欄,然後輸入API的工作。 –

0

您正在使用header("location: xxx");可用於重定向到給定的網址。您可以撥打短信RESTAPI在簡單的PHP函數來發送短信:

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); 
} 
} 

你也可以使用PHP類發送短信 http://www.phpclasses.org/package/9522-PHP-Send-SMS-messages-with-Spring-Edge-API.html

有兩個文件在上面的類:

  • sendms.php - 類文件調用短信網關restAPI
  • 測試。php - 用於測試短信功能的示例文件。

本課程使用spring edge短信網關提供程序API,您可以根據需要爲其他任何短信提供程序定製RestAPI url和params。