1
hostinger.com에서 호스팅되는 원격 Apache 서버에 ESP8266 12F 마이크로 컨트롤러를 연결하려고합니다. 그러나 클라이언트가 연결할 수 없습니다. 내가해야 할 일은 서버의 mysql 데이터베이스에 약간의 수치를 쓰는 것이다. 마이크로 컨트롤러를 모바일 핫스팟에 연결했지만 서버에 연결할 수 없습니다. 여기 내 코드는 다음과 같습니다ESP8266을 원격 서버에 연결할 수 없습니다
#include<ESP8266WiFi.h>
#define SS_PIN 4
#define RST_PIN 5
#define host http://smartlbus.esy.es/
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
static const int RXPin = 0, TXPin = 16;
static const uint32_t GPSBaud = 9600;
// The TinyGPS++ object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
WiFi.mode(WIFI_STA);
WiFi.begin("smartbus","qwerty123");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
if(WiFi.status()==WL_CONNECTED) Serial.println("Connected to wifi");
}
void loop() {
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (client.connect("http://www.smartlbus.esy.es", httpPort)) {
Serial.println("Connected to server");
while (ss.available() > 0)
if (gps.encode(ss.read()))
{
double lat,lng;
float speed;
if (gps.location.isValid())
{
lat=gps.location.lat();
lng=gps.location.lng();
speed=gps.speed.value();
}
String data = "lat1=" + (String) lat + "&lng1=" + (String)lng + "&speed=" + (String)speed;
client.println("POST /add.php HTTP/1.1");
client.println("Host: www.smartlbus.esy.es");
client.println("Content-Type: application/x-www-form-urlencoded");
client.print("Content-Length: ");
client.println(data.length());
client.println();
client.print(data);
delay(500);
}
}
else{
Serial.println("Cannot cannect to server..");
}
// Look for new cards
다음은 PHP 코드입니다 :
<?php
include 'dbConnect.php';
if($_SERVER['REQUEST_METHOD']=='POST'){
//Getting values
$lat = $_POST['lat1'];
$lng = $_POST['lng1'];
$speed = $_POST['speed'];
$id = $_POST['busid'];
//Creating an sql query
$sql = "INSERT INTO status (bus_id,latitude,longitude,speed) VALUES ('$id','$lat','$lng','$speed')";
//Executing query to database
mysqli_query($con,$sql);
//Closing the database
mysqli_close($con);
}
?>
이 저를 도와주세요.
당신이 포트 8000''해야한다는 확신? (대개 '80 '). 여기에서 포트 80에서 볼 수 있지만 포트 8000 번 밖으로 ... – dandavis
오, 미안 해요 오타였습니다. Idk는 그것이 그것을 cre아 먹었던 방법. –
CURL을 통해 데이터를 전송하려고 시도했지만 올바르게 응답하지 않습니다. 서버가 작동하는지 확인하십시오. – eyllanesc