Links2004 / arduinoWebSockets

arduinoWebSockets
GNU Lesser General Public License v2.1
1.86k stars 551 forks source link

Using GSM with WebSockets #197

Closed x0ryuu closed 7 years ago

x0ryuu commented 7 years ago

Hello @Links2004 :)!

I would like using Ai Thinker A6 (GSM/GPRS) with this library instead of ESP8266 wifi client.

I can create a class with methods called equal as "wifi client class" using A6 module, but I don't know where I can insert my own class and using it with your library.

Could you give me a clue about it, please?

Thanks! Your library is really awesome!

Links2004 commented 7 years ago

at first you need to add your CPU here (if you not use an all ready existing one an AVR, STM or ESP for example): https://github.com/Links2004/arduinoWebSockets/blob/master/src/WebSockets.h#L55 set the options based on what make the most sens for your hardware.

next define a Network stack:

#define NETWORK_AI_A6_GSM        (4)

https://github.com/Links2004/arduinoWebSockets/blob/master/src/WebSockets.h#L69

then auto select it here: https://github.com/Links2004/arduinoWebSockets/blob/master/src/WebSockets.h#L79 based on a CPU / BOARD define form the compiler / IDE.

then include the needed header files and define the TCP Client and Server class:

#elif (WEBSOCKETS_NETWORK_TYPE == NETWORK_AI_A6_GSM)

#include <UIPEthernet.h>
#define WEBSOCKETS_NETWORK_CLASS UIPClient
#define WEBSOCKETS_NETWORK_SERVER_CLASS UIPServer

https://github.com/Links2004/arduinoWebSockets/blob/master/src/WebSockets.h#L139

as long your class has the same API then all the Network stuff in Arduino ( Client/Stream and Server class ) it will work fine.

x0ryuu commented 7 years ago

Thanks for answering me @Links2004 :)!!

But I think that I explains me wrong, I go again.

No, I do not want to put this library inside the A6, it's a bit different, I currently have an ESP8266 which communicates via UART (Rx, Tx) with an Ai Thinker GSM / GPRS A6 module, the WebSockets library will be within ESP8266.

The A6 module uses AT commands to make HTTP requests using TCP, I created a client class that has methods that use these AT commands to make the requests, what I want is for the WebSockets library which is within the ESP8266 to use my client class which implements AT commands of the A6 module, in other words, the WebSockets library will never be inside the A6 module, it will be inside the ESP8266 but I want it use my class that communicates with the A6 module to make the requests instead of the client class that comes with the ESP8266 module inside its source code.

For example, here : https://github.com/Links2004/arduinoWebSockets/blob/master/src/WebSocketsClient.cpp#L119

You use a internal client class from ESP8266, is that right?

I want to change this and using my own client class with A6 comunication.

Thanks!

Links2004 commented 7 years ago

the process is the same ;)

line 199 you linked is exklusive for the SSL on the ESP the generic client part is done with:

_client.tcp = new WEBSOCKETS_NETWORK_CLASS();

https://github.com/Links2004/arduinoWebSockets/blob/master/src/WebSocketsClient.cpp#L130

which class will be used is controlled via the defines.

for the network type ESP8266 they are here: https://github.com/Links2004/arduinoWebSockets/blob/master/src/WebSockets.h#L108-L122

skip the new CPU part from my first post, in your case you only need a new "Network type" its possible to combine different network type with different platforms, for example ESP8266 CPU with NETWORK_ENC28J60 will work fine. https://github.com/Links2004/arduinoWebSockets/blob/master/src/WebSockets.h#L77-L86

if the A6 can handle all requirements via the AT command interface is the bigger question.

if you can get raw TCP access to the data stream on the A6 think looking good, but when the HTTP stack is build in the A6 I dont think this is possible.

x0ryuu commented 7 years ago

I see..

A6 module is able to send specific HTTP headers but it can not keep open a connection and you can not access to HTTP stack because it is build inside...

So I guess it is impossible what I want!

So, do you know any solution to use GSM/GPRS with WebSockets instead of a wifi connection?

Links2004 commented 7 years ago

currently I am not aware of a GSM module that will handle that, but I never did deep researche for it.

if your project not need to run a long time with battery or you have access to line power, may simple use a cheap and/or old Android Phone and open an wifi hotspot with it.

if this is not an option you need to find a module where you can open a TCP connection to a server and then send and receive data from it (basic TCP client stuff)

or a GSM module where the firmware is open.