我正在使用带有脉冲传感器的NodeMCU“ESP8266”,我想在XAMPP服务器上将模拟数据发送到我的数据库。
我将此代码用于WiFi客户端:
#include <ESP8266WiFi.h>
const char* ssid = "tabark";
const char* password = "tabarekghassan";
int value;
const char* host = "http://localhost/mysql0.php?value"+ value;
void setup() {
Serial.begin(115200);
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
/* Explicitly set the ESP8266 to be a WiFi-client, otherwise, it by default,
would try to act as both a client and an access-point and could cause
network-issues with your other WiFi-devices on your WiFi-network. */
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
delay(5000);
value=analogRead(A0);
Serial.print(value);
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
// We now create a URI for the request
String url = "/input/";
url += "&value=";
url += value;
Serial.print("Requesting URL: ");
Serial.println(url);
// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 5000) {
Serial.println(">>> Client Timeout !");
client.stop();
return;
}
}
// Read all the lines of the reply from server and print them to Serial
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("closing connection");
}
我用它来做数据库:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$value = $_GET["value"];
$conn = mysql_connect($servername, $username, $password);
if ($conn) {
echo "Connected successfully";
}
else {
echo "connection failed";
}
$conndb = mysql_select_db('database', $conn);
echo "<br>";
$sql_insert ="insert into pulsesensor(value) values ('$value')";
if($sql_insert){
echo "insert successfull";
}
else {
echo "insert failed";
}
echo "<br>";
$result = mysql_query($sql_insert);
if($result){
echo "insert successfull";
}
else {
echo "insert failed" . mysql_error($result);
}
?>
当我把值放在URL中时,值会保存在数据库中,但它不起作用,我得到了这个结果:
那该怎么办?
答案 0 :(得分:0)
好像你正在做一个不允许的操作:
<item android:state_focused="true">
<shape android:shape="rectangle" >
<corners android:radius="0dip" />
<stroke android:width="0dip" android:color="#cb1307" />
<solid android:color="#cb1307"/>
</shape>
</item>
<item >
<shape android:shape="rectangle" >
<corners android:radius="10dip" />
<gradient android:angle="270" android:startColor="#fff" android:endColor="#89F5D7" />
</shape>
</item>