【问题标题】:Send SMS via Arduino without GSM通过没有 GSM 的 Arduino 发送短信
【发布时间】:2017-09-03 01:08:27
【问题描述】:

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

【问题讨论】:

  • 您可以发送电子邮件。有图书馆。
  • 你的问题有点含糊。您想在将数据插入数据库时​​向手机号码发送确认消息,我认为这是您的目标。

标签: arduino


【解决方案1】:

我认为您想在将数据插入数据库时​​向数字发送消息。最好的方法是使用在线消息服务提供商。

我建议你clickatell(它提供了一些免费的消息用于测试),以后你可以购买api如果你想要它用于商业目的。首先,您需要在他们的site 上注册。然后登录它,您可以在那里进行短信集成。在那里可以选择创建新的集成。输入名称、描述,然后选择环境和 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代码,在消息中发送到手机。

【讨论】:

  • 这将帮助您解决问题。如果您有任何疑问,请随时询问
  • 兄弟你的代码不工作..请帮忙。我的 API 链接是vas.banglalinksgsm.com/sendSMS/…,当我按下 ardunio 标签 velue 的按钮成功插入但没有发送短信时。当我复制此 API 链接并粘贴浏览器地址栏并输入时,API 正在工作。
  • 这个 API 有什么问题,它运行良好.. vas.banglalinksgsm.com/sendSMS/…
  • 您是通过 http 请求从 arduino 访问您的 php 页面,还是 PHP 代码写在您的 arduino 代码中?
【解决方案2】:

您正在使用header("location: xxx"); 可用于重定向到给定的网址。您可以在简单的 PHP 函数中调用 sms RestApi 来发送短信:

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

上面的类中有两个文件:

  • sendsms.php - 调用短信网关restAPI的类文件
  • test.php - 测试短信功能的示例文件。

该类使用spring edge sms gateway provider API,您可以根据需要为任何其他sms provider自定义RestAPI url和params。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多