I'm having issues getting my ESP32 SIM7000G to connect to a websocket.
I'm using a websocket tester piesocket.com with no reponse. Is there anything I need to add or change for this to work? Thanks for any suggestions.
#include <Arduino.h>
#include <WebSocketsClient.h>
#include <SocketIOclient.h>
SocketIOclient socketIO;
#define SerialMon Serial
#define SerialAT Serial1
#define TINY_GSM_MODEM_SIM7000SSL
#define TINY_GSM_RX_BUFFER 1024
#define SerialAT Serial1
#include <TinyGsmClient.h>
#ifdef DUMP_AT_COMMANDS
#include <StreamDebugger.h>
StreamDebugger debugger(SerialAT, SerialMon);
TinyGsm modem(debugger);
#else
TinyGsm modem(SerialAT);
#endif
#define UART_BAUD 9600
#define PIN_DTR 25
#define PIN_TX 27
#define PIN_RX 26
#define PWR_PIN 4
#define LED_PIN 12
const char apn[] = "h2g2";
const char user[] = "";
const char pass[] = "";
void modemPowerOn()
{
pinMode(PWR_PIN, OUTPUT);
digitalWrite(PWR_PIN, LOW);
delay(1000); //Datasheet Ton mintues = 1S
digitalWrite(PWR_PIN, HIGH);
}
void modemPowerOff()
{
pinMode(PWR_PIN, OUTPUT);
digitalWrite(PWR_PIN, LOW);
delay(1500); //Datasheet Ton mintues = 1.2S
digitalWrite(PWR_PIN, HIGH);
}
void modemRestart()
{
modemPowerOff();
delay(1000);
modemPowerOn();
}
void socketIOEvent(socketIOmessageType_t type, uint8_t * payload, size_t length)
{
switch(type)
{
case sIOtype_DISCONNECT:
Serial.printf("Disconnected!");
break;
case sIOtype_CONNECT:
Serial.printf("Connected to url: %s\n", payload);
}
}
void setup()
{
SerialMon.begin(115200);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, HIGH);
modemPowerOn();
SerialAT.begin(UART_BAUD, SERIAL_8N1, PIN_RX, PIN_TX);
delay(10000);
String modemInfo = modem.getModemInfo();
SerialMon.print("Modem: ");
SerialMon.println(modemInfo);
SerialMon.print("Waiting for network...");
if (!modem.waitForNetwork(240000L))
{
SerialMon.println(" fail");
delay(10000);
return;
}
SerialMon.println(" OK");
if (modem.isNetworkConnected())
{
SerialMon.println("Network connected");
}
SerialMon.print(F("Connecting to APN: "));
SerialMon.print(apn);
if (!modem.gprsConnect(apn, user, pass))
{
SerialMon.println(" fail");
delay(10000);
return;
}
socketIO.begin("wss://demo.piesocket.com/v3/channel_1?api_key=VCXCEuvhGcBDP7XhiJJUDvR1e1D3eiVjgZ9VRiaV¬ify_self",443);
socketIO.onEvent(socketIOEvent);
}
void loop()
{}