can´t emit via ethernet to my server on javascript? - websocket

hello, good day, I am making an example with a 5500 chip in esp32 with the socketioclient library, but when I want to send the json to my server, they are only left on the waiting list and I don't know what is happening to me, before all this an error message about invalid mbox appeared and I added the following line of code esp_netif_init(); and it was fixed, but once entering the loop the following happens:
serial monitor:
Starting WebServer on ESP32 with W5x00 using Ethernet_Generic Library with Large Buffer
Ethernet_Generic v2.4.0
[ETG] Default SPI pinout:
[ETG] MOSI: 23
[ETG] MISO: 19
[ETG] SCK: 18
[ETG] SS: 5
[ETG] =========================
[ETG] ESP32 setCsPin: 5
[ETG] W5100 init, using SS_PIN_DEFAULT = 22 , new ss_pin = 10 , W5100Class::ss_pin = 5
[ETG] Chip is W5500
[ETG] W5100::init: W5500, SSIZE = 8192
[ETG] Currently Used SPI pinout:
[ETG] MOSI: 23
[ETG] MISO: 19
[ETG] SCK: 18
[ETG] SS: 5
[ETG] =========================
Using mac index = 1
Connected! IP address: 192.168.10.147
Speed: 100 MB, Duplex: FULL DUPLEX, Link status: LINK
LLego a la parte de initwebsocket y task
termino inits
[SIoC] add packet 42["setRele",{"Dato":"hola"}]
[SIoC] add packet 42["getPrueba",{"name":"hola ese","SERVIDOR":"HOLA MUNDO"}]
[SIoC] Disconnected!
[SIoC] add packet 42["setRele",{"Dato":"hola"}]
[SIoC] add packet 42["getPrueba",{"name":"hola ese","SERVIDOR":"HOLA MUNDO"}]
[SIoC] Disconnected!
[SIoC] add packet 42["setRele",{"Dato":"hola"}]
[SIoC] add packet 42["getPrueba",{"name":"hola ese","SERVIDOR":"HOLA MUNDO"}]
[SIoC] Disconnected!
then the loop remains without emitting it just remains as shown above
sketch:
/****************************************************************************************************************************
WebServer.ino
Ethernet_Generic is a library for the W5x00 Ethernet shields trying to merge the good features of
previous Ethernet libraries
Built by Khoi Hoang https://github.com/khoih-prog/Ethernet_Generic
*****************************************************************************************************************************/
/*
The Arduino board communicates with the shield using the SPI bus. This is on digital pins 11, 12, and 13 on the Uno
and pins 50, 51, and 52 on the Mega. On both boards, pin 10 is used as SS. On the Mega, the hardware SS pin, 53,
is not used to select the Ethernet controller chip, but it must be kept as an output or the SPI interface won't work.
*/
#include "defines.h"
#include <SocketIoClient.h>
#include <Arduino_JSON.h>
#include <tcpip_adapter.h>
//TaskHandle_t Task1;
SocketIoClient socketIO;
//void Task1code( void * parameter ){
// Serial.print("Task1 is running on core ");
// Serial.println(xPortGetCoreID());
// while(1){
// socketIO.loop();
// delay(100);
// }
//}
//
//
void initWebSocket()
{
// server address, port and URL
socketIO.begin("192.168.10.59",8000);
// event handler for the event message
socketIO.on("asignacion",getresponse);
//socketIO.on("getPrueba",getresponse);
socketIO.loop();
delay(5000);
}
void getresponse(const char *payload, size_t length){
Serial.printf("response: ",payload);
String data = String(payload);
data.replace("\\","");
JSONVar dato = JSON.parse(data);
Serial.println(dato["litros"]);
}
void setup()
{
Serial.begin(115200);
while (!Serial && millis() < 5000);
Serial.print("\nStarting WebServer on "); Serial.print(BOARD_NAME);
Serial.print(F(" with ")); Serial.println(SHIELD_TYPE);
Serial.println(ETHERNET_GENERIC_VERSION);
#if (USING_SPI2)
#if defined(CUR_PIN_MISO)
ETG_LOGWARN(F("Default SPI pinout:"));
ETG_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI);
ETG_LOGWARN1(F("MISO:"), CUR_PIN_MISO);
ETG_LOGWARN1(F("SCK:"), CUR_PIN_SCK);
ETG_LOGWARN1(F("SS:"), CUR_PIN_SS);
ETG_LOGWARN(F("========================="));
#endif
#else
ETG_LOGWARN(F("Default SPI pinout:"));
ETG_LOGWARN1(F("MOSI:"), MOSI);
ETG_LOGWARN1(F("MISO:"), MISO);
ETG_LOGWARN1(F("SCK:"), SCK);
ETG_LOGWARN1(F("SS:"), SS);
ETG_LOGWARN(F("========================="));
#endif
#if defined(ESP32)
// You can use Ethernet.init(pin) to configure the CS pin
//Ethernet.init(10); // Most Arduino shields
//Ethernet.init(5); // MKR ETH shield
//Ethernet.init(0); // Teensy 2.0
//Ethernet.init(20); // Teensy++ 2.0
//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
#endif
#ifndef USE_THIS_SS_PIN
#define USE_THIS_SS_PIN 5 //22 // For ESP32
#endif
ETG_LOGWARN1(F("ESP32 setCsPin:"), USE_THIS_SS_PIN);
// Must use library patch for Ethernet, EthernetLarge libraries
// ESP32 => GPIO2,4,5,13,15,21,22 OK with Ethernet, Ethernet2, EthernetLarge
// ESP32 => GPIO2,4,5,15,21,22 OK with Ethernet3
//Ethernet.setCsPin (USE_THIS_SS_PIN);
Ethernet.init (USE_THIS_SS_PIN);
// start the ethernet connection and the server:
// Use DHCP dynamic IP and random mac
uint16_t index = millis() % NUMBER_OF_MAC;
// Use Static IP
//Ethernet.begin(mac[index], ip);
Ethernet.begin(mac[index]);
//SPIClass SPI2(HSPI);
//Ethernet.begin(mac[index], &SPI2);
// Just info to know how to connect correctly
// To change for other SPI
#if defined(CUR_PIN_MISO)
ETG_LOGWARN(F("Currently Used SPI pinout:"));
ETG_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI);
ETG_LOGWARN1(F("MISO:"), CUR_PIN_MISO);
ETG_LOGWARN1(F("SCK:"), CUR_PIN_SCK);
ETG_LOGWARN1(F("SS:"), CUR_PIN_SS);
ETG_LOGWARN(F("========================="));
#else
ETG_LOGWARN(F("Currently Used SPI pinout:"));
ETG_LOGWARN1(F("MOSI:"), MOSI);
ETG_LOGWARN1(F("MISO:"), MISO);
ETG_LOGWARN1(F("SCK:"), SCK);
ETG_LOGWARN1(F("SS:"), SS);
ETG_LOGWARN(F("========================="));
#endif
Serial.print(F("Using mac index = "));
Serial.println(index);
Serial.print(F("Connected! IP address: "));
Serial.println(Ethernet.localIP());
if ( (Ethernet.getChip() == w5500) || (Ethernet.getAltChip() == w5100s) )
{
Serial.print(F("Speed: ")); Serial.print(Ethernet.speedReport());
Serial.print(F(", Duplex: ")); Serial.print(Ethernet.duplexReport());
Serial.print(F(", Link status: ")); Serial.println(Ethernet.linkReport());
}
Serial.println("LLego a la parte de initwebsocket y task");
Serial.println("termino inits");
// tcpip_adapter_init();
// for (int i = TCPIP_ADAPTER_IF_STA; i < TCPIP_ADAPTER_IF_MAX; i++) {
// if (tcpip_adapter_is_netif_up((tcpip_adapter_if_t)i))
// ESP_LOGI(TAG, "interface %i up ", i);
// else
// ESP_LOGI(TAG, "interface %i down ", i);
// }
esp_netif_init();//ojo con esta funcion https://gitter.im/espressif/arduino-esp32?at=607b291f06e2e024e85cdf50
initWebSocket();
// xTaskCreatePinnedToCore(Task1code,"Task1",10000,NULL,1,&Task1,0);
}
void loop()
{
//socketio.loop();
//socketIO.emit("getPrueba","{\"hello world\"}");
//socketIO.emit("plainString", "\"this is a plain string\"");
socketIO.emit("setRele","{\"Dato\":\"hola\"}");
delay(500);
//socketIO.emit("app","{\"name\":\"hola ese\",\"chava\":\"hola chava\"}");//esta libreria solo maneja archivos json
socketIO.emit("getPrueba","{\"name\":\"hola ese\",\"SERVIDOR\":\"HOLA MUNDO\"}");
//socketIO.emit("setData","{\"Dato\":\"hola\",\"Dato2\":\"Andre\"}");
//socketIO.on("get",getresponse);
delay(500);
socketIO.loop();
}
i only use two events to emit to the server they are setRele and getprueba as shown in the loop
server java script:
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http,{allowEIO3: true ,cors: {origins: ['http://localhost:4200', 'http://localhost']}});
var port = process.env.PORT || 8080;
app.get('/', (req, res) => {
console.log("app works");
});
io.on('connection', (socket) => {
console.log(socket.id);
/**Catalogos */
// socket.emit("GetConfiguracion","{\"code\":\"ECOA-0179\",\"cambio\":\"0\",\"idRespuesta\":\"1\",\"Pines\":[{},{}]}");
// socket.emit("Reiniciar","{\"CodigoMDC\":\"ECOA-0179\"}");
// socket.emit("SetRelee","{\"code\":\"ECOA-0179\",\"f\":\"2022/04/26 03:51:33\",\"p\":\"26\",\"v\":\"1.00\"}");
socket.on("stateChanged", (params) => {
console.log(params); // x8WIv7-mJelg7on_ALbx
});
socket.on("getPrueba", (params) => {
console.log(params); // x8WIv7-mJelg7on_ALbx
});
socket.on("setRele", (params) => {
console.log(params); // x8WIv7-mJelg7on_ALbx
//socket.emit("SetRelee","{\"code\":\"ECOA-0179\",\"f\":\"2022/04/26 03:51:33\",\"p\":\"26\",\"v\":\"1.00\"}");
});
socket.on("ConfiguracionAplicada", (params) => {
console.log(params); // x8WIv7-mJelg7on_ALbx
});
socket.on('disconnect', () =>
{
console.log("Desconectado id: ",socket.id);
});
});
http.listen(port, () => {
console.log('listening on :' + port);
});
If someone could help me, it would be very helpful. Thank you. I'm new to ethernet connectivity. I hope you understand.

Related

How to Install WiFi

This is about PlftformIO extension to VSCode.
Code:
/*********
Rui Santos
Complete project details at http://randomnerdtutorials.com
*********/
// Load Wi-Fi library
#include <WiFi.h>
// Replace with your network credentials
const char* ssid = "linksys";
const char* password = "goskomstat";
// Set web server port number to 80
WiFiServer server(80);
// Variable to store the HTTP request
String header;
// Auxiliar variables to store the current output state
String output26State = "off";
String output5State = "off";
// Assign output variables to GPIO pins
const int output26 = 26;
const int output5 = 5;
// Current time
unsigned long currentTime = millis();
// Previous time
unsigned long previousTime = 0;
// Define timeout time in milliseconds (example: 2000ms = 2s)
const long timeoutTime = 2000;
void setup() {
Serial.begin(115200);
// Initialize the output variables as outputs
pinMode(output26, OUTPUT);
pinMode(output5, OUTPUT);
// Set outputs to LOW
digitalWrite(output26, LOW);
digitalWrite(output5, LOW);
// Connect to Wi-Fi network with SSID and password
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
// Print local IP address and start web server
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
server.begin();
}
void loop(){
WiFiClient client = server.available(); // Listen for incoming clients
if (client) { // If a new client connects,
currentTime = millis();
previousTime = currentTime;
Serial.println("New Client."); // print a message out in the serial port
String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected() && currentTime - previousTime <= timeoutTime) { // loop while the client's connected
currentTime = millis();
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out the serial monitor
header += c;
if (c == '\n') { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println("Connection: close");
client.println();
// turns the GPIOs on and off
if (header.indexOf("GET /26/on") >= 0) {
Serial.println("GPIO 26 on");
output26State = "on";
digitalWrite(output26, HIGH);
} else if (header.indexOf("GET /26/off") >= 0) {
Serial.println("GPIO 26 off");
output26State = "off";
digitalWrite(output26, LOW);
} else if (header.indexOf("GET /5/on") >= 0) {
Serial.println("GPIO 5 on");
output5State = "on";
digitalWrite(output5, HIGH);
} else if (header.indexOf("GET /5/off") >= 0) {
Serial.println("GPIO 5 off");
output5State = "off";
digitalWrite(output5, LOW);
}
// Display the HTML web page
client.println("<!DOCTYPE html><html>");
client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
client.println("<link rel=\"icon\" href=\"data:,\">");
// CSS to style the on/off buttons
// Feel free to change the background-color and font-size attributes to fit your preferences
client.println("<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}");
client.println(".button { background-color: #4CAF50; border: none; color: white; padding: 16px 40px;");
client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}");
client.println(".button2 {background-color: #555555;}</style></head>");
// Web Page Heading
client.println("<body><h1>ESP32 Web Server</h1>");
// Display current state, and ON/OFF buttons for GPIO 26
client.println("<p>GPIO 26 - State " + output26State + "</p>");
// If the output26State is off, it displays the ON button
if (output26State=="off") {
client.println("<p><button class=\"button\">ON</button></p>");
} else {
client.println("<p><button class=\"button button2\">OFF</button></p>");
}
// Display current state, and ON/OFF buttons for GPIO 27
client.println("<p>GPIO 5 - State " + output5State + "</p>");
// If the output27State is off, it displays the ON button
if (output5State=="off") {
client.println("<p><button class=\"button\">ON</button></p>");
} else {
client.println("<p><button class=\"button button2\">OFF</button></p>");
}
client.println("</body></html>");
// The HTTP response ends with another blank line
client.println();
// Break out of the while loop
break;
} else { // if you got a newline, then clear currentLine
currentLine = "";
}
} else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
}
}
// Clear the header variable
header = "";
// Close the connection
client.stop();
Serial.println("Client disconnected.");
Serial.println("");
}
}
Error:
* Executing task: platformio run
Processing nodemcu-32s (platform: espressif32; board: nodemcu-32s; framework: espidf)
---------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/nodemcu-32s.html
PLATFORM: Espressif 32 (6.0.1) > NodeMCU-32S
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
- framework-espidf # 3.50000.0 (5.0.0)
- tool-cmake # 3.16.4
- tool-esptoolpy # 1.40400.0 (4.4.0)
- tool-ninja # 1.7.1
- toolchain-esp32ulp # 1.23500.220830 (2.35.0)
- toolchain-xtensa-esp32 # 11.2.0+2022r1
Reading CMake configuration...
LDF: Library Dependency Finder -> https://----.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio/build/nodemcu-32s/src/main.o
src/main.c:7:10: fatal error: WiFi.h: No such file or directory
**************************************************************
* Looking for WiFi.h dependency? Check our library registry!
*
* CLI > platformio lib search "header:WiFi.h"
* Web > https://registry.platformio.org/search?q=header:WiFi.h
*
**************************************************************
7 | #include <WiFi.h>
| ^~~~~~~~
compilation terminated.
Archiving .pio/build/nodemcu-32s/esp-idf/app_trace/libapp_trace.a
Indexing .pio/build/nodemcu-32s/esp-idf/app_trace/libapp_trace.a
Archiving .pio/build/nodemcu-32s/esp-idf/app_update/libapp_update.a
Indexing .pio/build/nodemcu-32s/esp-idf/app_update/libapp_update.a
Compiling .pio/build/nodemcu-32s/bootloader_support/src/bootloader_clock_init.o
Compiling .pio/build/nodemcu-32s/bootloader_support/bootloader_flash/src/bootloader_flash.o
Compiling .pio/build/nodemcu-32s/bootloader_support/src/bootloader_mem.o
*** [.pio/build/nodemcu-32s/src/main.o] Error 1
====================================== [FAILED] Took 2.12 seconds ======================================
* The terminal process "platformio 'run'" terminated with exit code: 1.
* Terminal will be reused by tasks, press any key to close it.
ini:
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:nodemcu-32s]
platform = espressif32
board = nodemcu-32s
framework = espidf
lib_deps = arduino-libraries/WiFi#^1.2.7
Library has been installed:
michael#michael:~/Documents/PlatformIO/Projects/blink$ pio pkg install --library "arduino-libraries/WiFi#^1.2.7"
Resolving nodemcu-32s dependencies...
Library Manager: WiFi#1.2.7 is already installed
Could you help me?
You don't "install wifi" separately. It's part of the Arduino framework for the ESP32 and it depends on other parts of the Arduino framework. It's not meant to be used separately.
Your platformio.ini file specifies ESP-IDF as the framework to use when building your program. ESP-IDF has its own WiFi API. If you're using ESP-IDF, use its WiFi functions.
The Arduino framework is built over ESP-IDF, so you can call some ESP-IDF functions from Arduino programs. You cannot, however, call Arduino functions from an ESP-IDF program as ESP-IDF knows nothing about Arduino.
If you want to use Arduino functions, build an Arduino program by setting the framework in your platformio.ini file to be arduino.
framework = arduino
Basically, pick one framework and stick with it. Don't try to mix Arduino functions into your ESP-IDF program.

TTGO ESP32 + GSM 800l - Read SMS - TinyGSM

on my code i can send an sms to my target number but i don't know how to read or receive sms from target number
the tinyGSM library doesn't have the read member function and i don't know how to use AT commands
void setup() {
// Set console baud rate
SerialMon.begin(115200);
// Keep power when running from battery
Wire.begin(I2C_SDA, I2C_SCL);
bool isOk = setPowerBoostKeepOn(1);
SerialMon.println(String("IP5306 KeepOn ") + (isOk ? "OK" : "FAIL"));
// Set modem reset, enable, power pins
pinMode(MODEM_PWKEY, OUTPUT);
pinMode(MODEM_RST, OUTPUT);
pinMode(MODEM_POWER_ON, OUTPUT);
digitalWrite(MODEM_PWKEY, LOW);
digitalWrite(MODEM_RST, HIGH);
digitalWrite(MODEM_POWER_ON, HIGH);
// Set GSM module baud rate and UART pins
SerialAT.begin(115200, SERIAL_8N1, MODEM_RX, MODEM_TX);
delay(3000);
// Restart SIM800 module, it takes quite some time
// To skip it, call init() instead of restart()
SerialMon.println("Initializing modem...");
modem.restart();
// use modem.init() if you don't need the complete restart
// Unlock your SIM card with a PIN if needed
if (strlen(simPIN) && modem.getSimStatus() != 3 ) {
modem.simUnlock(simPIN);
}
// To send an SMS, call modem.sendSMS(SMS_TARGET, smsMessage)
String smsMessage = "Hello from ESP32!";
/*if(modem.sendSMS(SMS_TARGET, smsMessage))
{
SerialMon.println(smsMessage);
}
else{
SerialMon.println("SMS failed to send");
}*/
SerialAT.println("AT"); //Once the handshake test is successful, it will back to OK
SerialAT.println("AT+CMGF=1"); // Configuring TEXT mode
SerialAT.println("AT+CNMI=1,2,0,0,0"); // Decides how newly arrived SMS messages should be handled
}
void loop()
{
//readSMS(1);
//delay(1);
}

Arduino(ESP8266) to laravel websocket channel subscription problem

i'm working on an IoT project which needs to connect to a laravel based socket server.
on laravel side all things are working just as should be but the problem is in arduino side which is a ESP8266 module being program by Arduino IDE.
i want to use Links2004/arduinoWebSockets library to connect to server.
it connects but i can't determine on which channel it should be.
is there any way on this library to tell the channel device should be on?
I gratefully appreciate any help :)
Arduino Test Code:
/*
Esp8266 Websockets Client
This sketch:
1. Connects to a WiFi network
2. Connects to a Websockets server
3. Sends the websockets server a message ("Hello Server")
4. Prints all incoming messages while the connection is open
Hardware:
For this sketch you only need an ESP8266 board.
Created 15/02/2019
By Gil Maimon
https://github.com/gilmaimon/ArduinoWebsockets
*/
#include <ArduinoWebsockets.h>
#include <ESP8266WiFi.h>
const char* ssid = "****"; //Enter SSID
const char* password = "******"; //Enter Password
const char* websockets_server_host = "xxx.xxx.xxx.xxx"; //Enter server adress -- serverip_or_name
const uint16_t websockets_server_port = 6001; // Enter server port
bool connected;
using namespace websockets;
WebsocketsClient client;
void setup() {
Serial.begin(115200);
// Connect to wifi
WiFi.begin(ssid, password);
// Wait some time to connect to wifi
for(int i = 0; i < 10 && WiFi.status() != WL_CONNECTED; i++) {
Serial.print(".");
delay(1000);
}
// Check if connected to wifi
if(WiFi.status() != WL_CONNECTED) {
Serial.println("No Wifi!");
return;
}
Serial.println("Connected to Wifi, Connecting to server.");
// try to connect to Websockets server
connected = client.connect(websockets_server_host, websockets_server_port, "/app/ab_key");
if(connected) {
Serial.println("Connecetd!");
client.send("Hello Server");
} else {
Serial.println("Not Connected!");
}
// run callback when messages are received
client.onMessage([&](WebsocketsMessage message) {
Serial.print("Got Message: ");
Serial.println(message.data());
});
}
void loop() {
if(connected) {
Serial.println("Connecetd!");
client.send("Hello Server");
} else {
connected = client.connect(websockets_server_host, websockets_server_port, "/app/ab_key");
Serial.println("try!");
}
// let the websockets client check for incoming messages
if(client.available()) {
client.poll();
}
delay(500);
}
terminal view of laravel websocket: laravel websocket

socketio server not connecting to ESP8266

I am facing problems while connecting to my SocketIo server through my ESP8266.
I have my ESP connected to my Wifi and my Node Server is running on localhost.
I have the following code in ESP8266
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
#include <SocketIoClient.h>
//192.168.1.37 --My IP Address
SocketIoClient webSocket;
const char* ssid = "ssid"; // SSID
const char* password = "pass"; // Password
const char* host = "192.168.1.37"; // Server IP (localhost)
const int port = 8080; // Server Port
const char* url = "http://localhost:8080/test";
void event(const char * payload, size_t length) {
Serial.println("Message");
}
void setup() {
Serial.begin(115200);
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500); // 5ms Delay
Serial.print(".");
}
Serial.print("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("Connecting To Socket");
webSocket.on("event", event);
webSocket.begin("192.168.1.37", 8080);
}
void loop() {
if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
delay(3000); //Send a request every 3 seconds
webSocket.loop();
Serial.println("Retrying ....");
}
Also my Server side code is in JavaScript.
var io = socket(server);
io.on('connection', (socket) => {
console.log('made socket connection', socket.id);
socket.on("ESP", function(data){
socket.emit('Hi ESP, ESP called', data);
console.log("Socket Working !");
});
console.log('made socket connection', socket.id);
socket.on("connect", function(data){
socket.emit('Hi ESP connect called', data);
console.log("Socket Working !");
});
});
But i keep on receiving this output in the Serial Monitor.
Also there is no request received on my server.
11:37:09.729 -> ..........WiFi connected
11:37:14.129 -> IP address:
11:37:14.129 -> 192.168.1.13
11:37:14.129 -> Connecting To Socket
11:37:17.245 -> Retrying ....
11:37:17.245 -> [SIoC] Disconnected!
11:37:17.245 -> [SIoC] event disconnected not found. 1 events available
11:37:20.230 -> Retrying ....
11:37:20.230 -> [SIoC] Disconnected!
11:37:20.230 -> [SIoC] event disconnected not found. 1 events available
i have same issue
[SIoC] Disconnected!
[SIoC] Connected to url: /socket.io/?transport=websocket
[SIoC] Disconnected!
[SIoC] Disconnected!
[SIoC] Disconnected!
i change server side socket io config to this :
const io = require("socket.io")(server, {
cors: {
origin: "*",
methods: ["GET", "POST"],
transports: ["websocket", "polling"],
credentials: true,
},
allowEIO3: true,
});
and Fix !
I have faced the same issue. It is fixed when I changed the socket.io version to ^2.3.0
Change the socket io version to ^2.3.0 in package.json, delete node modules and reinstall the packages using npm install command
I had the same issue and changed:
WiFi.begin(ssid, password);
to
WiFiMulti.addAP(ssid, pass);
and it connects fine.
PS: I used <SocketIOclient.h>

How to Wake ES8266 from deep sleep on Dev board NodeMCU

Basically, my project uses a force-sensing resistor to detect occupancy on the chair. The ESP8266 WiFi would wake from the sleep mode and send an update to the server. If there is no occupancy, the ESP8266 goes back to sleep.
My project uses Wiolink, a dev board that uses a ESP8266 WiFi chip. Hence, it is quite impossible to connect GPIO 16 to RST to wake up ( or reset ) the device.
Deep sleep is predefined at a set amount of time using this function ESP.deepsleep(). Is it possible to wake up with an external interrupt such as the force sensing resistor?
String apiKey = ""; // const char* ssid = ""; // wifi username const
char* password = ""; // wifi password
void setup() // Defines the initial condition of the hardware board.
{
Serial.begin(115200); delay(10);
}
void loop() // Defines the loop condition of the hardware board. {
sensorReading = analogRead(A0);
if(sensorReading >= 150) // Condition when someone is sitting;
{
//Wake ESP8266
//perform server update
}
if(sensorReading <=149) // Condition for no one sitting;
{
Serial.println("Going into deep sleep");
ESP.deepSleep(); //
}

Resources