Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CoAP and Websocket do not work #32

Open
3Mohammed2013 opened this issue Mar 4, 2018 · 1 comment
Open

CoAP and Websocket do not work #32

3Mohammed2013 opened this issue Mar 4, 2018 · 1 comment

Comments

@3Mohammed2013
Copy link

Hi every one
I face this problem that show to me is run but the localhost for coap and websocket when i was paste on the browser was not work

-14ISK:~/devify-server$ node websocket-broker-server.js && node coap-broker-server.js
WoT/WebSocket server is listening at ws://localhost:8000

@jollen
Copy link
Member

jollen commented Mar 14, 2018

@3Mohammed2013

To send the sensory data to the p2p network in WebSocket, use the URI ws://[ip_address:port]/object/[name]/send in which you must specify the IP address, port and user-defined object name. For example, there is one peer node running at the address 192.168.1.2:8001 within the p2p network.

ws://192.168.1.2:8001/object/frontdoor/send

The following example periodically sends simulated temperature data to the wot server.

var WebSocketClient = require('websocket').client;

var client = new WebSocketClient();

client.on('connectFailed', function(error) {
    console.log('Connect Error: ' + error.toString());
});

client.on('connect', function(connection) {
    console.log('WebSocket client connected');
    connection.on('error', function(error) {
        console.log("Connection Error: " + error.toString());
    });
    connection.on('close', function() {
        console.log('echo-protocol Connection Closed');
    });

    function sendNumber() {
        if (connection.connected) {
            var number = Math.round(Math.random() * 0xFFFFFF);
            var lucky = Math.round(Math.random() * 100 + 1);
            var obj = {temperature: lucky};

            console.log('[SEND]', JSON.stringify(obj));

            connection.sendUTF(JSON.stringify(obj));
            setTimeout(sendNumber, 1000);
        }
    }
    sendNumber();
});

client.connect('ws://192.168.1.2:8001/object/frontdoor/send', '');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants