GithubHelp home page GithubHelp logo

node-websockets's Introduction

node-websockets's People

Contributors

danielleadams avatar hunterloftis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-websockets's Issues

error

i have tried to deploy this on heroku but after a successful deployment when i check to heroku logs, there i got an error
2020-04-16T20:31:39.855061+00:00 app[web.1]: const wss = new Server({ server });
2020-04-16T20:31:39.855062+00:00 app[web.1]: ^
2020-04-16T20:31:39.855067+00:00 app[web.1]:
2020-04-16T20:31:39.855068+00:00 app[web.1]: ReferenceError: server is not defined
2020-04-16T20:31:39.855070+00:00 app[web.1]: at Object. (/app/server.js:13:26)

How to manage esp32 client connect to heroku websocket nodejs server

Dear Sir ,

I have a nodejs server running on a local machine connect to esp32 client that working fine .

Server:
const express = require('express')
const app = express()
const server = require('http').createServer(app);
const WebSocket = require('ws');

const wss = new WebSocket.Server({ server:server });

wss.on('connection', function connection(ws) {
console.log('A new client Connected!');
ws.send('Welcome New Client!');

ws.on('message', function incoming(message) {
console.log('received: %s', message);

server.listen(83, () => console.log(Lisening on port :83))

client side ๐Ÿ‘

#include <WiFi.h>
#include <WiFiClient.h>
//#include <WebSocketsServer.h>
#include <WebSockets.h>
#include <WebSocketsClient.h>
//#include <WebServer.h>

const char* ssid = "X";
const char* password = "X";

IPAddress local_IP(192, 168, 1,65);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255,255,255,0);
IPAddress primaryDNS(8, 8, 8, 8);

// Initialise websockets, web server and servo
//WebSocketsServer webSocket = WebSocketsServer(1337);

WebSocketsClient webSocket;

void setup(void) {

Serial.begin(115200);
// Initialize the output variables as outputs

// Connect to Wi-Fi network with SSID and password
if (!WiFi.config(local_IP, gateway, subnet, primaryDNS)) {
Serial.println("STA Failed to configure");
}

// Connect to Wi-Fi network with SSID and password
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
// while (WiFi.status() != WL_CONNECTED) {
// delay(500);
//digitalWrite(32,HIGH);
//
// //Serial.print(".");
// }
// Print local IP address and start web server
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());

webSocket.begin("192.168.1.3", 83, "/");
delay(4000);
webSocket.onEvent(webSocketEvent);

// Configure web server to host HTML files
//server.onNotFound({
// if(!handleFileRead(server.uri()))
// server.send(404, "text/plain", "FileNotFound");
// });
// server.begin();
Serial.println("HTTP server started");

}

void loop() {
// put your main code here, to run repeatedly:
webSocket.loop();
//String message= "hello from client";
//webSocket.broadcastTXT(message);

}

void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {

//const int PROG = digitalRead(27);

switch(type) {

// Runs when a user disconnects
case WStype_DISCONNECTED: {
  Serial.printf("[WSc] Disconnected!\n");
  break;
}

// Runs when a user connects
case WStype_CONNECTED: {
//  IPAddress ip = webSocket.remoteIP(num);
  Serial.printf("[WSc] Connected to url: %s\n", payload);
       
        webSocket.sendTXT("hello i am Connected");
       
       }
  break;
case WStype_TEXT:{
  Serial.printf("[WSc] get text: %s\n", payload);
    String text = String((char *) &payload[0]);

  Serial.println (text);
    break;     

}

// send data to server
// webSocket.sendBIN(payload, length);
// break;
// case WStype_ERROR:
// case WStype_FRAGMENT_TEXT_START:
// case WStype_FRAGMENT_BIN_START:
// case WStype_FRAGMENT:
// case WStype_FRAGMENT_FIN:
// break;
}

}

How i manage to put this server on heroku cloud to be working?

Connect through an external client

Do I need to change some config in heroku to enable external clients to connect?

I tried to connect using a socket.io client running locally and pointing to wss://herokusite:port but I was never able to connect

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.