GET request in LUA - ">>" after send request - lua

I send my Lua code by Arduino IDE.
My sketch in Arduino:
#include <SoftwareSerial.h>
SoftwareSerial ESPserial(2, 3); // RX | TX
void setup()
{
Serial.begin(9600); // communication with the host computer
//while (!Serial) { ; }
// Start the software serial for communication with the ESP8266
ESPserial.begin(9600);
Serial.println("");
Serial.println("Remember to to set Both NL & CR in the serial monitor.");
Serial.println("Ready");
Serial.println("");
delay(1000);
}
void loop()
{
// listen for communication from the ESP8266 and then write it to the serial monitor
if ( ESPserial.available() ) { Serial.write( ESPserial.read() ); }
// listen for user input and send it to the ESP8266
if ( Serial.available() ) { ESPserial.write( Serial.read() ); }
}
I open serial port and send my code:
conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) print(payload) end)
conn:connect(8080, "192.168.0.100")
conn:send("GET /json.htm?type=command&param=udevice&idx=3&nvalue=0&svalue=69 HTTP/1.1\r\nHost: 192.168.0.100\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n")
But my ESP return ">>" after last command.. there is screen
When I replace conn:send on this:
conn:send("GET / HTTP/1.1\r\nHost: 192.168.0.100\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n")
All is correct, I take respond from server...
Thanks for help!

Related

LCD ESP8266WiFi access point Send Text

hello i am trying to send data to lcd screen
,but they arrive as GET/ DATO /HTTP 1.1
I ONLY NEED TO ARRIVE DATA AND DELETE (GET/ /HTTP 1.1)
I am used to the esp8266 by wifi in access point mode the program works well
request is the data that arrives at the arduino terminal
}
if (request.indexOf("") != -1) { //////SHIPPING PART
// enviar
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print(request);
delay(1000);
}
Send Text
I just want to send text so this is what I hope to ahieve
SEND DATO
DELETE GET/ /HTTP 1.1
#include <ESP8266WiFi.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const char *ssid_AP = "LCDAP";
const char *Password_AP = "12345678";
WiFiServer server(80);
LiquidCrystal_I2C lcd(0x27,2,16);
void setup(){
lcd.init(); // initialize the lcd
lcd.backlight();
lcd.setCursor(2,0);
lcd.print("LCD Ready");
Serial.begin(115200);
delay(10);
delay(1000);
WiFi.mode(WIFI_AP);
WiFi.softAP(ssid_AP,Password_AP);
Serial.println("WiFi conected");
Serial.println();
WiFi.printDiag(Serial);
Serial.print("AP direccion IP: ");
Serial.println(WiFi.softAPIP());
// Start the server
server.begin();
Serial.println("Server started");
}
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){
delay(1);
}
// Read the first line of the\r %d\n
String request = client.readStringUntil('\n');
Serial.println(request);
client.flush();
if (request.indexOf("/LCDBORRAR") != -1) {
lcd.clear();
delay(1000);
}
if (request.indexOf("") != -1) { ////// send text
// enviar
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print(request);
delay(1000);
}
delay(1);
Serial.println("Client disonnected");
Serial.println("");
}
req.replace(" HTTP/1.1", ""); // Para quitar HTTP/1.1
req.replace("GET /", ""); // Para quitar GET /

Sending data to TELNET app with ESP8266 and arduino uno

I started to test the ESP8266 module, i wrote in the serial port this commands: AT, AT+RST, AT+CWMODE=1(station mode), AT+CWLAP, AT+CWJAP="My network name","password", AT+CIPMUX=1, AT+CIPSERVER=1,80, AT+CIPSEND=0,"numer of char of my string", "MyMessage", AT+CIPCLOSE=0 and it work, its sends the message to my phone.
Now I try to do some function that sends automatically those commands, but when i get to the sending message part it gives me an error.
I post my code below:
#include <SoftwareSerial.h>
SoftwareSerial ESPserial(9, 10); // RX | TX
void setup()
{
Serial.begin(9600); // communication with the host computer
// Start the software serial for communication with the ESP8266
ESPserial.begin(9600);
delay(1000);
Serial.println("");
Serial.println("Remember to to set Both NL & CR in the serial monitor.");
Serial.println("Ready");
Serial.println("");
trimiteDate("AT+IPR=9600",1000);
trimiteDate("AT",1000);
trimiteDate("AT+RST",1000);
trimiteDate("AT+CWMODE=1",1000);
trimiteDate("AT+CWLAP",1000);
trimiteDate("AT+CWJAP=\"DIGI_d61430\",\"ddcc29eb\"",1000);
trimiteDate("AT+CIFSR",1000);
trimiteDate("AT+CIPMUX=1",1000);
trimiteDate("AT+CIPSERVER=1,80",1000);
scrie("Sir de caractere",1000);
}
void loop()
{
// listen for communication from the ESP8266 and then write it to the serial monitor
if ( ESPserial.available() ) { Serial.write( ESPserial.read() ); }
// listen for user input and send it to the ESP8266
if ( Serial.available() ) { ESPserial.write( Serial.read() ); }
}
void trimiteDate(String comanda, const int timp ){
ESPserial.println(comanda);
while ( ESPserial.available() ) { Serial.write( ESPserial.read() ); }
while ( Serial.available() ) { ESPserial.write( Serial.read() );}
delay(timp);
}
void scrie(String sir, const int timp){
int lungimeSir = sir.length();
String startTransmisie = "AT+CIPSEND=1,";
String stopTransmisie = "AT+CIPCLOSE=0";
String sirDate = startTransmisie + lungimeSir;
trimiteDate(sirDate,1000);
ESPserial.println(sir);
trimiteDate(stopTransmisie,1000);
delay(timp);
}

ESP8266 crashes after simple http request

I am working with the NodeMCU V3 module. Whenever I try to make an http request to my server, the module crashes.
Here's the code:
void setup() {
WiFi.begin("wifi-name", "wifi-password");
while (WiFi.status() != WL_CONNECTED) { //Wait for the WiFI to connect }
}
void loop() {
HTTPClient http;
WiFiClient client;
http.begin( client, "server-address" );
int httpCode = http.GET();
String payload = http.getString(); //Get the response payload
Serial.println(httpCode); //Print HTTP return code
Serial.println(payload); //Print request response payload
http.end(); //Close connection
delay( 1000 );
}
Here's the result, as seen in the serial monitor:
200
["JSON response from the server"]
Exception (28):
epc1=0x40212e82 epc2=0x00000000 epc3=0x00000000 excvaddr=0x000001b6 depc=0x00000000
>>>stack>>>
ctx: cont
sp: 3ffffc90 end: 3fffffc0 offset: 01a0
3ffffe30: 00000000 4bc6a7f0 0000333f 3ffee5f8
3ffffe40: 00000000 00000000 4bc6a7f0 00000000
[...]
3fffffb0: feefeffe feefeffe 3ffe84e8 40100c41
<<<stack<<<
The strange thing is that it retrieves the response from the server correctly, but then, about one second later, it spits out the exception to the serial monitor and resets. At first I thought it could be because I am running ESP8266WebServer at the same time, but it still crashes even when I run the most basic example I could find on the internet. I tried compiling the same code on the Arduino IDE instead of PlatformIO, or even using a different NodeMCU, to no avail.
EDIT: After playing around a bit more, it seems like setting the delay to at least 10 seconds makes the NodeMCU crash after 3 requests instead of after the first one. Could it be that it's memory overflows after a few requests? Am I missing a crucial part that should prepare the ESP8266 for a new request?
There is no need to re-create the WiFi and HTTP clients in the loop() over and over again. You can declare them once globally. Here's a stable version of this simple sketch:
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESPHTTPClient.h>
HTTPClient http;
WiFiClient client;
void setup() {
Serial.begin(115200);
Serial.println();
WiFi.begin("****", "****");
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("done.");
}
void loop() {
http.begin(client, "http://httpbin.org/get"); // <1KB payload
// http.begin(client, "http://www.geekstips.com/esp8266-arduino-tutorial-iot-code-example/"); // 30KB payload
int httpCode = http.GET();
String payload = http.getString(); //Get the response payload
Serial.println(httpCode); //Print HTTP return code
Serial.println(payload); //Print request response payload
http.end(); //Close connection
Serial.printf("Free heap: %d\n", ESP.getFreeHeap());
delay(1000);
}
The reported free heap is very stable over time.
Please take note of the second URL I added for testing in the commented line. That http.getString() is convenient and works well for small resources but yields unexpected i.e. wrong results for larger resources - you only see a small fraction of the body printed to the console.
For larger payloads you should use the low-level WiFiClient directly and read/parse the response line-by-line or character-by-character. See the documentation at https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/client-examples.html for a template.
void loop()
{
WiFiClient client;
Serial.printf("\n[Connecting to %s ... ", host);
if (client.connect(host, 80))
{
Serial.println("connected]");
Serial.println("[Sending a request]");
client.print(String("GET /") + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n" +
"\r\n"
);
Serial.println("[Response:]");
while (client.connected() || client.available())
{
if (client.available())
{
String line = client.readStringUntil('\n');
Serial.println(line);
}
}
client.stop();
Serial.println("\n[Disconnected]");
}
else
{
Serial.println("connection failed!]");
client.stop();
}
delay(5000);
}

ESP8266 disconnects immediately after connecting to server

`I am new to ESP8266.
I have created a website hosted on 000webhost, however whenever I connect to the server using the ESP8266's AT command set the connection closes instantly. I am trying to send some data from my Arduino board to the website via the ESP8266
Therefore I can not send any message to the website.
Any ideas on how to handle this issue? Thanks!
Output on the serial monitor
Arduino Code
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); //RX,TX
int LEDPIN = 13;
void setup()
{
pinMode(LEDPIN, OUTPUT);
Serial.begin(9600); // communication with the host computer
//while (!Serial) { ; }
// Start the software serial for communication with the ESP8266
mySerial.begin(9600);
Serial.println("");
Serial.println("Remember to to set Both NL & CR in the serial monitor.");
Serial.println("Ready");
Serial.println("");
}
void loop()
{
digitalWrite(13,1);
// listen for communication from the ESP8266 and then write it to the serial
monitor
if ( mySerial.available() ) { Serial.write( mySerial.read() ); }
// listen for user input and send it to the ESP8266
if ( Serial.available() )
// { mySerial.write( mySerial.print("AT+CWMODE=1") ); }
{ mySerial.write( Serial.read() ); }
}
PHP Code:
<?php
if(isset($_GET['stat'])){
$status=$_GET['stat'];
$a2="<!DOCTYPE html><br><html><br>" . $status ."<br><html>";
$fp = fopen("a2.php", "w");
fwrite($fp, $a2);
fclose($fp);
echo $status;
}
else {echo "house";}
?>

GET request failed in Arduino-Uno

I am trying to access a simple web page running in my Rpi-server using ESP8266 and Arduino.
I have refereed this similar SO question , but it's not the solution for my problem.
Here is my current Arduino Code :
#include "WiFiEsp.h"
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(2,3); // RX, TX
#endif
char ssid[] = "RPi"; // your network SSID (name)
char pass[] = "raspberry"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
char server[] = "192.168.50.1";
// Initialize the Ethernet client object
WiFiEspClient client;
void setup()
{
// initialize serial for debugging
Serial.begin(9600);
// initialize serial for ESP module
Serial1.begin(9600);
// initialize ESP module
WiFi.init(&Serial1);
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue
while (true);
}
// attempt to connect to WiFi network
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network
status = WiFi.begin(ssid, pass);
}
// you're connected now, so print out the data
Serial.println("You're connected to the network");
printWifiStatus();
Serial.println();
Serial.println("Starting connection to server...");
// if you get a connection, report back via serial
if (client.connect(server, 80)) {
Serial.println("Connected to server");
// Make a HTTP request
client.println("GET /simple.html HTTP/1.1");
client.println("Host: 192.168.50.1");
client.println("Connection: close");
client.println();
}
}
void loop()
{
while (client.available()) {
char c = client.read();
Serial.write(c);
}
// if the server's disconnected, stop the client
if (!client.connected()) {
Serial.println();
Serial.println("Disconnecting from server...");
client.stop();
// do nothing forevermore
while (true);
}
void printWifiStatus()
{
// print the SSID of the network you're attached to
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength
long rssi = WiFi.RSSI();
Serial.print("Signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
Output:
Starting connection to server...
[WiFiEsp] Connecting to 192.168.50.1
Connected to server
[WiFiEsp] Data packet send error (2)
[WiFiEsp] Failed to write to socket 3
[WiFiEsp] Disconnecting 3
My simple.html looks like this.
<html>
<body>
<p>1</p>
</body>
</html>
}
I accessed to this page from web browser and it shows the content properly.
What is missing here?
Thanks in advance.
Try this line in your code
client.print("GET /simple.html HTTP/1.0\r\n\r\n");

Resources