{"action":"created","issue":{"url":"https://api.github.com/repos/Links2004/arduinoWebSockets/issues/132","repository_url":"https://api.github.com/repos/Links2004/arduinoWebSockets","labels_url":"https://api.github.com/repos/Links2004/arduinoWebSockets/issues/132/labels{/name}","comments_url":"https://api.github.com/repos/Links2004/arduinoWebSockets/issues/132/comments","events_url":"https://api.github.com/repos/Links2004/arduinoWebSockets/issues/132/events","html_url":"https://github.com/Links2004/arduinoWebSockets/issues/132","id":184624973,"number":132,"title":"[Socket.io Websocket] Sends Disconnect message without stop and doesn't connect to the server!","user":{"login":"WisterDesigns","id":18012605,"avatar_url":"https://avatars.githubusercontent.com/u/18012605?v=3","gravatar_id":"","url":"https://api.github.com/users/WisterDesigns","html_url":"https://github.com/WisterDesigns","followers_url":"https://api.github.com/users/WisterDesigns/followers","following_url":"https://api.github.com/users/WisterDesigns/following{/other_user}","gists_url":"https://api.github.com/users/WisterDesigns/gists{/gist_id}","starred_url":"https://api.github.com/users/WisterDesigns/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WisterDesigns/subscriptions","organizations_url":"https://api.github.com/users/WisterDesigns/orgs","repos_url":"https://api.github.com/users/WisterDesigns/repos","events_url":"https://api.github.com/users/WisterDesigns/events{/privacy}","received_events_url":"https://api.github.com/users/WisterDesigns/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2016-10-22T11:23:57Z","updated_at":"2016-10-24T08:10:22Z","closed_at":null,"body":"Hello everyone,\r\nI'm using the WebSocketsClient.h library and I have some problems, The NodeMCU 12E doesn't connect to the Webserver don't know why.\r\n**Arduino Code:**\r\n```cpp\r\n/*\r\n * WebSocketClientSocketIO.ino\r\n *\r\n *  Created on: 06.06.2016\r\n *\r\n */\r\n\r\n#include <Arduino.h>\r\n\r\n#include <ESP8266WiFi.h>\r\n#include <ESP8266WiFiMulti.h>\r\n\r\n#include <WebSocketsClient.h>\r\n\r\n#include <Hash.h>\r\n\r\nESP8266WiFiMulti WiFiMulti;\r\nWebSocketsClient webSocket;\r\n\r\n\r\n#define USE_SERIAL Serial\r\n\r\n#define MESSAGE_INTERVAL 30000\r\n#define HEARTBEAT_INTERVAL 25000\r\n\r\nuint64_t messageTimestamp = 0;\r\nuint64_t heartbeatTimestamp = 0;\r\nbool isConnected = false;\r\n\r\nvoid webSocketEvent(WStype_t type, uint8_t * payload, size_t lenght) {\r\n\r\n\r\n    switch(type) {\r\n        case WStype_DISCONNECTED:\r\n            USE_SERIAL.printf(\"[WSc] Disconnected!\\n\");\r\n            isConnected = false;\r\n            break;\r\n        case WStype_CONNECTED:\r\n            {\r\n                USE_SERIAL.printf(\"[WSc] Connected to url: %s\\n\",  payload);\r\n                isConnected = true;\r\n\r\n\t\t\t    // send message to server when Connected\r\n                // socket.io upgrade confirmation message (required)\r\n\t\t\t\twebSocket.sendTXT(\"5\");\r\n            }\r\n            break;\r\n        case WStype_TEXT:\r\n            USE_SERIAL.printf(\"[WSc] get text: %s\\n\", payload);\r\n\r\n\t\t\t// send message to server\r\n\t\t\t// webSocket.sendTXT(\"message here\");\r\n            break;\r\n        case WStype_BIN:\r\n            USE_SERIAL.printf(\"[WSc] get binary lenght: %u\\n\", lenght);\r\n            hexdump(payload, lenght);\r\n\r\n            // send data to server\r\n            // webSocket.sendBIN(payload, lenght);\r\n            break;\r\n    }\r\n\r\n}\r\n\r\nvoid setup() {\r\n    // USE_SERIAL.begin(921600);\r\n    USE_SERIAL.begin(115200);\r\n\r\n    //Serial.setDebugOutput(true);\r\n    USE_SERIAL.setDebugOutput(true);\r\n\r\n    USE_SERIAL.println();\r\n    USE_SERIAL.println();\r\n    USE_SERIAL.println();\r\n\r\n      for(uint8_t t = 4; t > 0; t--) {\r\n          USE_SERIAL.printf(\"[SETUP] BOOT WAIT %d...\\n\", t);\r\n          USE_SERIAL.flush();\r\n          delay(1000);\r\n      }\r\n\r\n    WiFiMulti.addAP(\"Linksys - HotBox\", \"123123\");\r\n\r\n    //WiFi.disconnect();\r\n    while(WiFiMulti.run() != WL_CONNECTED) {\r\n        delay(100);\r\n    }\r\n\r\n    webSocket.begin(\"192.168.1.105\", 81);\r\n    //webSocket.setAuthorization(\"user\", \"Password\"); // HTTP Basic Authorization\r\n    webSocket.onEvent(webSocketEvent);\r\n\r\n}\r\n\r\nvoid loop() {\r\n    webSocket.loop();\r\n\r\n    if(isConnected) {\r\n\r\n        uint64_t now = millis();\r\n\r\n        if(now - messageTimestamp > MESSAGE_INTERVAL) {\r\n            messageTimestamp = now;\r\n            // example socket.io message with type \"messageType\" and JSON payload\r\n            webSocket.sendTXT(\"42[\\\"messageType\\\",{\\\"greeting\\\":\\\"hello\\\"}]\");\r\n        }\r\n        if((now - heartbeatTimestamp) > HEARTBEAT_INTERVAL) {\r\n            heartbeatTimestamp = now;\r\n            // socket.io heartbeat message\r\n            webSocket.sendTXT(\"2\");\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n**Arduino Serial Monitor:**\r\n```\r\n[SETUP] BOOT WAIT 4...\r\nscandone\r\nstate: 0 -> 2 (b0)\r\nstate: 2 -> 3 (0)\r\nstate: 3 -> 5 (10)\r\nadd 0\r\naid 4\r\ncnt \r\n\r\nconnected with Linksys - HotBox, channel 11\r\ndhcp client start...\r\n[SETUP] BOOT WAIT 3...\r\n[SETUP] BOOT WAIT 2...\r\n[SETUP] BOOT WAIT 1...\r\nip:192.168.1.109,mask:255.255.255.0,gw:192.168.1.1\r\n[WSc] Disconnected!\r\n[WSc] Disconnected!\r\n[WSc] Disconnected!\r\n[WSc] Disconnected!\r\n[WSc] Disconnected!\r\n[WSc] Disconnected!\r\n[WSc] Disconnected!\r\n[WSc] Disconnected!\r\n```\r\n\r\n**Socket.io & Node.JS server Codes:**\r\n```js\r\nvar express = require('express');\r\napp = express();\r\nserver = require('http').createServer(app);\r\nio = require('socket.io').listen(server);\r\n\r\nserver.listen(81);\r\napp.use(express.static('public'));\r\n\r\nio.sockets.on('connection', function (socket) {\r\n\r\n    console.log('Socket connected: ' + socket.conn.remoteAddress);\r\n\r\n    socket.on('led', function (data) {\r\n    });\r\n\r\n\r\n    socket.on('disconnect', function(socket) {\r\n        console.log('Socket disconnected');\r\n    });\r\n});\r\n\r\n\r\nconsole.log(\"Server is running.\");\r\n```\r\n\r\nPicture: http://prntscr.com/cxgvx0\r\n\r\nThanks for everyone's help!\r\n"},"comment":{"url":"https://api.github.com/repos/Links2004/arduinoWebSockets/issues/comments/255675112","html_url":"https://github.com/Links2004/arduinoWebSockets/issues/132#issuecomment-255675112","issue_url":"https://api.github.com/repos/Links2004/arduinoWebSockets/issues/132","id":255675112,"user":{"login":"Barman54","id":23026278,"avatar_url":"https://avatars.githubusercontent.com/u/23026278?v=3","gravatar_id":"","url":"https://api.github.com/users/Barman54","html_url":"https://github.com/Barman54","followers_url":"https://api.github.com/users/Barman54/followers","following_url":"https://api.github.com/users/Barman54/following{/other_user}","gists_url":"https://api.github.com/users/Barman54/gists{/gist_id}","starred_url":"https://api.github.com/users/Barman54/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Barman54/subscriptions","organizations_url":"https://api.github.com/users/Barman54/orgs","repos_url":"https://api.github.com/users/Barman54/repos","events_url":"https://api.github.com/users/Barman54/events{/privacy}","received_events_url":"https://api.github.com/users/Barman54/received_events","type":"User","site_admin":false},"created_at":"2016-10-24T08:10:22Z","updated_at":"2016-10-24T08:10:22Z","body":"Hi, \r\nI used yout library on 8266 with success but then I tried to make a websocketsserver on a mega. I get some errors because the esp lib has some more members as  the ethernet lib has. After commenting out these lines I got a websocketsclient which continuously says 'disconnected' (allthough no clients have been connected). \r\n\r\nTo make this message not too long I attach the .ino file (as .txt). I started with the esp version and changed\r\n- added debug.h because of 'hexdump'\r\n- added Hash.h and the commented it out \r\n- commented out 'IPAddress ip = webSocket.remoteIP(num)' bev=cause I could not find a comparable member in WebSocketServer\r\n- changed webSocket.begin(); to webSocket.beginSocketIO(\"192.168.0.38\", 81); but the latter is no member of class WebSocket\r\n\r\nCan you point me to the right direction?\r\n[WebSocketServerAVR.txt](https://github.com/Links2004/arduinoWebSockets/files/547212/WebSocketServerAVR.txt)\r\n\r\n"}}
{"actor":{"display_login":"Barman54"}}