application.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* To compile using make CLI, create a folder under \firmware\user\applications and copy application.cpp there.
  2. * Then, copy src files under particleWebSocket folder.
  3. */
  4. #include "application.h"
  5. #include "particleWebSocket/WebSocketsClient.h"
  6. WebSocketsClient webSocket;
  7. void webSocketEvent(WStype_t type, uint8_t* payload, size_t length)
  8. {
  9. switch (type)
  10. {
  11. case WStype_DISCONNECTED:
  12. Serial.printlnf("[WSc] Disconnected!");
  13. break;
  14. case WStype_CONNECTED:
  15. Serial.printlnf("[WSc] Connected to URL: %s", payload);
  16. webSocket.sendTXT("Connected\r\n");
  17. break;
  18. case WStype_TEXT:
  19. Serial.printlnf("[WSc] get text: %s", payload);
  20. break;
  21. case WStype_BIN:
  22. Serial.printlnf("[WSc] get binary length: %u", length);
  23. break;
  24. }
  25. }
  26. void setup()
  27. {
  28. Serial.begin(9600);
  29. WiFi.setCredentials("[SSID]", "[PASSWORD]", WPA2, WLAN_CIPHER_AES_TKIP);
  30. WiFi.connect();
  31. webSocket.begin("192.168.1.153", 85, "/ClientService/?variable=Test1212");
  32. webSocket.onEvent(webSocketEvent);
  33. }
  34. void loop()
  35. {
  36. webSocket.sendTXT("Hello world!");
  37. delay(500);
  38. webSocket.loop();
  39. }