я пытаюсь соединить mysql и nodemcu с php (laravel), но когда я запускаю скрипт arduino, возникает ошибка, которую я не знаю. кто-нибудь может мне помочь?
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h>
#include<DHT.h> DHT dht(14, DHT11);
//#define TRIGGER_PIN 5 //D1
//#define ECHO_PIN 4 //D2
const char* ssid = "PS-E3";
const char* password = "Pesona30";
const char* host = "192.168.1.19";
WiFiClient client;
const int httpPort = 80;
String url; long duration, distance;
float kelembaban, suhu;
unsigned long timeout;
void setup() {
Serial.begin(9600);
dht.begin();
delay(10);
// pinMode(TRIGGER_PIN, OUTPUT);
// pinMode(ECHO_PIN, INPUT);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
void baca_suhu(){
kelembaban = dht.readHumidity();
suhu = dht.readTemperature();
Serial.print("kelembaban : ");
Serial.println(kelembaban);
Serial.print("Suhu : ");
Serial.println(suhu);
}
void loop() {
// Serial.print("baca jarak ");
// baca_jarak(); baca_suhu();
Serial.print("connecting to ");
Serial.println(host);
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
//return;
}
// We now create a URI for the request
url = "localhost:8000/cuaca/tampil/save/";
url += suhu;
url += "/";
url += kelembaban;
Serial.print("Requesting URL: ");
Serial.println(url);
// This will send the request to the server
client.print(String("POST ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
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");
Serial.println();
delay(5000);
}
на этом хосте ip уже с ip моего компьютера. и HTTP-порт уже то же самое с xampp, я не понимаю, почему это происходит ошибка в любом случае, это мой скрипт в laravel
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use App\Http\Controllers;
class SimpanController extends Controller
{
public function index(){
$cuaca = DB::table('tb_cuaca')->orderBy('Kode','ASC')->paginate(10);
//passing data ke view
return view('tampilcuaca',['cuaca' => $cuaca]);
}
public function save($suhu, $kelembaban)
{
$date = date("Y-m-d");
// insert data ke table sekolah
DB::table('tb_cuaca')->insert([
'Suhu' => $suhu,
'Kelembaban' => $kelembaban,
'Tanggal' => $date
]);
// alihkan halaman ke halaman tampilsekolah
echo "berhasil";
return redirect('/tampildata');
}
public function tampildata(){
}
// public function store(Request $request)
// {
// // insert data ke table sekolah
// DB::table('tb_prestasi')->insert([
// 'Nama_Sekolah' => $request->nama,
// 'Prestasi' => $request->prestasi
// ]);
// // alihkan halaman ke halaman tampilsekolah
// return redirect('/prestasi');
// }
}
ошибка приходит как это
Connecting to PS-E3
scandone
.....scandone
state: 0 -> 2 (b0)
.state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 7
cnt
connected with PS-E3, channel 5
dhcp client start...
....ip:192.168.1.5,mask:255.255.255.0,gw:192.168.1.1
.
WiFi connected
IP address: 192.168.1.5
kelembaban : 79.00
Suhu : 29.10
connecting to 192.168.1.19
Requesting URL: localhost:8000/cuaca/tampil/save/29.10/79.00
HTTP/1.1 400 Bad Request
Date: Thu, 16 Jan 2020 05:41:33 GMT
Server: Apache/2.4.41 (Win64) OpenSSL/1.1.1c PHP/7.3.9
Vary: accept-language,accept-charset
Accept-Ranges: bytes
Connection: close
Content-Type: text/html; charset=utf-8
Content-Language: en
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Bad request!</title>
<link rev="made" href="mailto:postmaster@localhost" />
<style type="text/css"><!--/*--><![CDATA[/*><!--*/
body { color: #000000; background-color: #FFFFFF; }
a:link { color: #0000CC; }
p, address {margin-left: 3em;}
span {font-size: smaller;}
/*]]>*/--></style>
</head>
<body>
<h1>Bad request!</h1>
<p>
Your browser (or proxy) sent a request that
this server could not understand.
</p>
<p>
If you think this is a server error, please contact
the <a href="mailto:postmaster@localhost">webmaster</a>.
</p>
<h2>Error 400</h2>
<address>
<a href="/">192.168.1.19</a><br />
<span>Apache/2.4.41 (Win64) OpenSSL/1.1.1c PHP/7.3.9</span>
</address>
</body>
</html>
closing connection
помогите мне