esp-01 http
- Войдите на сайт для отправки комментариев
Чт, 19/04/2018 - 20:36
создал сервер http считающий подключения.
#include <ESP8266WiFi.h> #include <WiFiClient.h> #include <ESP8266WebServer.h> /* Set these to your desired credentials. */ const char *ssid = "TST_19_04_2018"; const char *password = "11111111"; //WiFiServer server(80); ESP8266WebServer server(80); int i=0; /* Just a little test message. Go to http://192.168.4.1 in a web browser * connected to this access point to see it. */ void handleRoot() { // char c = server.read(); // Serial.println(c); server.send(200, "You are connected"); Serial.print("connect: ");// Шлём в UART i=i+1; Serial.println(i);// Шлём в UART } void setup() { delay(1000); Serial.begin(9600); Serial.println(); Serial.print("Configuring access point..."); WiFi.softAP(ssid, password); IPAddress myIP = WiFi.softAPIP(); Serial.print("AP IP address: "); Serial.println(myIP); server.on("/", handleRoot); server.begin(); Serial.println("HTTP server started"); // sensors.begin(); //Serial.println("Diskonnected"); } void loop() { server.handleClient() ; //Serial.println("NEW Client");// Шлём в UART } // server.send(200, "text/plain", webString); // send to someones browser when asked
при попытки подключить с телефона (google chrome) счетчик считает и выводит в uart . при подключении с esp-01 счет не идет. подскажите какой должен быть запрос
/*
* This sketch sends data via HTTP GET requests to data.sparkfun.com service.
*
* You need to get streamId and privateKey at data.sparkfun.com and paste them
* below. Or just customize this script to talk to other HTTP servers.
*
*/
#include <ESP8266WiFi.h>
const char* ssid = "TST_19_04_2018";
const char* password = "11111111";
//const char* ssid = "ASUS";
//const char* password = "12345678";
const char* host = "192.168.4.1";
//const char* streamId = "....................";
//const char* privateKey = "....................";
void setup() {
Serial.begin(9600);
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");
delay(3000);
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
int value = 0;
void loop() {
delay(5000);
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
client.connect(host, httpPort) ;
String url = "";
url.trim();
//
client.print("GET http://" + host + (getWithoutPort? "" : (":" + host)) + doc + "&" + data + " HTTP/1.1\r\n" +
"Host: " + host + (getWithoutPort? "" : (":" + host)) + "\r\n" +
"Connection: Close\r\n" +
"\r\n");
//client.print("GET " + url + " HTTP/1.1\r\nHost: " + host + "\r\n" + "Connection: close\r\n\r\n");
client.flush(); // ждем отправки всех данных
// This will send the request to the server
// client.print(String("GET") + host + " 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 !");
// return;
char c = client.read();
Serial.println(c);
client.stop();
Serial.println("closing connection");
// 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");
}
к точке доступа подключается получает ip. но отправляет видимо неправильный запрос.
А он (телефон) не кеширует случаем? Может разок считал, а потом старое гонит?
страници не какой нет. просто считает подключения модуль и отключается связь с клиентом.
client.print("GET <a href="" title="http://"">http://"</a> + host + (getWithoutPort? "" : (":" + host)) + doc + "&" + data + " HTTP/1.1\r\n" +67"Host: "+ host + (getWithoutPort?"": (":"+ host)) +"\r\n"+68"Connection: Close\r\n"+69"\r\n");перепробовал уже разные запросы. и все не проходит
В строку запроса добавь рандомный параметр, чтобы убедиться, что дело не в кешировании. Типа такого: