| 77 | } |
| 78 | |
| 79 | void sendNewMessage() |
| 80 | { |
| 81 | if(!WifiStation.isConnected()) { |
| 82 | // Check if Esp8266 is connected to router |
| 83 | return; |
| 84 | } |
| 85 | |
| 86 | if(messageCount >= MESSAGES_TO_SEND) { |
| 87 | if(sendBinary) { |
| 88 | Serial.println(_F("End Websocket client session")); |
| 89 | wsClient.close(); // clean disconnect. |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | messageCount = 0; |
| 94 | sendBinary = true; |
| 95 | } |
| 96 | |
| 97 | if(sendBinary) { |
| 98 | uint8_t buf[10]; |
| 99 | os_get_random(buf, sizeof(buf)); |
| 100 | buf[1] = messageCount; |
| 101 | m_printHex(_F("Sending websocket binary"), buf, sizeof(buf)); |
| 102 | wsClient.sendBinary(buf, sizeof(buf)); |
| 103 | } else { |
| 104 | String message = F("Hello ") + String(messageCount); |
| 105 | Serial << _F("Sending websocket message: ") << message << endl; |
| 106 | wsClient.sendString(message); |
| 107 | } |
| 108 | |
| 109 | ++messageCount; |
| 110 | msgTimer.startOnce(); |
| 111 | } |
| 112 | |
| 113 | void STAGotIP(IpAddress ip, IpAddress mask, IpAddress gateway) |
| 114 | { |
nothing calls this directly
no test coverage detected