wotcity / wotcity-wot-framework

wotcity.io: the Web of Things programming framework
https://www.npmjs.com/package/wotcity.io
MIT License
17 stars 23 forks source link

CoAP and Websocket do not work #32

Open 3Mohammed2013 opened 6 years ago

3Mohammed2013 commented 6 years ago

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 commented 6 years ago

@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', '');