Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arduino和PHP_Php_Arduino - Fatal编程技术网

Arduino和PHP

Arduino和PHP,php,arduino,Php,Arduino,我使用Arduino Uno通过PHP插入数据并发送SMS API。像1234这样的值很好地插入到数据库中,但API不起作用,SMS也没有发送。我的PHP代码有什么问题?请帮忙。对不起我的英语 这是我的Arduino代码: #include <Client.h> #include <Ethernet.h> byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; byte subnet[] = {255, 255, 2

我使用Arduino Uno通过PHP插入数据并发送SMS API。像1234这样的值很好地插入到数据库中,但API不起作用,SMS也没有发送。我的PHP代码有什么问题?请帮忙。对不起我的英语

这是我的Arduino代码:

#include <Client.h>
#include <Ethernet.h>

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
byte subnet[] = {255, 255, 255, 0};
IPAddress ip(192, 168, 1, 103);
char server[] = "www.wscedu.com";
EthernetClient client;

void setup() {
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    Ethernet.begin(mac, ip);
    delay(1000);
  } else if (Ethernet.begin(mac) == 1) {
    Serial.print("IP Address:");
    Serial.println(Ethernet.localIP());
    delay(1000);
  }
}

void loop() {
  if (client.connect(server, 80) > 0) {
    client.print("GET /tag.php?");
    client.print("value=1234"); // This
    client.println(" HTTP/1.1");
    client.println("Host: www.wscedu.com");
    client.println("Connection: close");
    client.println(); // Empty line
    client.println(); // Empty line
    client.stop();
  }
  delay(10000);
}
#包括
#包括
字节mac[]={
0xDE、0xAD、0xBE、0xEF、0xFE、0xED
};
字节子网[]={255,255,255,0};
ip地址ip(192、168、1、103);
char服务器[]=“www.wscedu.com”;
以太网络客户端;
无效设置(){
if(以太网开始(mac)==0){
Serial.println(“未能使用DHCP配置以太网”);
以太网开始(mac,ip);
延迟(1000);
}else if(Ethernet.begin(mac)==1){
串行打印(“IP地址:”);
Serial.println(Ethernet.localIP());
延迟(1000);
}
}
void循环(){
如果(客户端连接(服务器,80)>0){
print(“GET/tag.php?”);
client.print(“value=1234”);//这个
client.println(“HTTP/1.1”);
client.println(“主机:www.wscedu.com”);
client.println(“连接:关闭”);
client.println();//空行
client.println();//空行
client.stop();
}
延迟(10 000);
}
这是我的PHP代码:tag.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.banglalinkgsm.com/sendSMS/sendSMS?msisdn='$phone_no'&message=tag Value: '".$tag."'&userID=userid123&passwd=wsr123&sender=WSC");
}
?>

如果标题(“位置:…”)被触发,那么您的代码没有问题,您应该检查API和sms网关的权限。我尝试了
curl www.www.wscedu.com/tag.php?value=1234
(这是您的Arduino所做的,我收到一条错误消息“重复输入”,但如果我更改
value=1238
,它似乎会重定向到sms网关,但收到一条消息“成功计数:0,失败计数:1”,这似乎表明问题出在sms网关上。请将url字符串分配给变量,如
$url=”https://vas.banglalinkgsm.com/sendSMS/sendSMS?msisdn=“$phone\u no”&message=tag Value:““$tag.”“&userID=userid123&passwd=wsr123&sender=WSC”
并将其打印出来查看是否正确?另外,我认为您需要urlencode($url)如果标题(“位置:…”)被触发,那么您的代码没有问题,您应该检查API和sms网关的权限。我尝试了
curl www.www.wscedu.com/tag.php?value=1234
(这就是您的Arduino所做的,我收到了一条错误消息“重复输入”,但如果我更改
value=1238
,它似乎会重定向到sms网关,但收到一条消息“成功计数:0和失败计数:1”,这似乎表明问题出在sms网关上。请将url字符串分配给变量,如
$url=”https://vas.banglalinkgsm.com/sendSMS/sendSMS?msisdn=“$phone_no”&message=标记值:”.$tag.“'&userID=userid123&passwd=wsr123&sender=WSC”
并将其打印出来以查看是否正确?此外,我认为您需要在发送字符串之前对其进行url编码($url)。