thinger-io / Arduino-Library

IOTMP Arduino Library for connecting devices to thinger.io #IoT
https://thinger.io
MIT License
114 stars 66 forks source link

Is not possible thinger.io + WebSocketsServer.h #17

Open vicen-t opened 6 years ago

vicen-t commented 6 years ago

Hi.

My project uses websockets. Everything is fine until I insert in the main loop () "thing.handle()". Right next comes the call to the socket loop.

Then the loop function of the socket stops working or it does erratically.

There's a solution?

alvarolb commented 6 years ago

Hi @vicen-t, I would require more information about the lib you are using and how you plan to integrate thinger.io with it.

Jus to know, why do you require to handle web sockets on the device? You can open web sockets over a thinger device, and query stream any resource at the frequency you want.

Best.

vicen-t commented 6 years ago

Hola Álvaro.

My project is composed of several esp8266 (nodemcu board) located in some rooms of my house. Every esp has a DHT22, and some of them are also connected to a relay or a TIP120 transistor for controlling led lights.

One ESP collects data from other ESP and take decisions. This ESP has a RTC clock and a HC-05 BT and is connected to de wifi/Internet. This ESP is acting as the "server". I can connect with it in a normal port (not websocket) and send orders with any mobile device.

All the ESP communicate using ESP-NOW, but some days ago the protocol stop working without reason. The project was connected to thinger.io over 6 month ago without problems, very solid.

After ESP-NOW collapse, I replaced it with a new own protocol based on websockets and json. The clients send own states to the server and the server send orders based on own decisions or on orders received via normal port throught mobile devices (man decisions).

Everything was good until I re-insert the module thinger.io. I planned to use thinger.io for displaying data over internet and provides a method for sending orders to the server over internet, extending the project outside my house.

Ok, it is a complex project ;)

This is a summary of the server sketch (I dont have access just now to the original code)

#include <WebSocketsServer.h>
#include <ThingerESP8266.h>

...
ThingerESP8266 thing(usuario, device_Id, device_credentials);
WebSocketsServer SOCKET = WebSocketsServer(9999);

...
SOCKET.begin();
SOCKET.onEvent(callbackfunc);   
...
// I dont pass wifi parameters to thing object
// I will connect with my own methods later:    **BOTH AP and STATION**
//thing.add_wifi(WiFi_ssid, WiFi_password);

void loop() {
  SOCKET.loop();
  thing.handle();  // When I insert this line the SOCKET object stop working or work erratically
}

Gracias por tu amabilidad, Álvaro.

Saludos!