mcollina / ponte

The M2M/IoT Bridge for REST developers
51 stars 5 forks source link

HTTP to MQTT example doesn't work #4

Closed matboehmer closed 10 years ago

matboehmer commented 10 years ago

The example of HTTP to MQTT doesn't work on my machine. I am using ponte 0.0.7. I am getting no errors, it is just that the subscribed client doesn't receive the message.

mcollina commented 10 years ago

Long story short: refer to http://npm.im/ponte for the the docs on the 0.0.7 version. That should work smoothly.

I'll be releasing a new version on NPM in the next few days, with this documentation.

chpradeep commented 10 years ago

I am also experiencing the same problem. When am running the command "ponte -v | bunyan" Its giving error

[2014-05-07T08:52:21.619Z] INFO: ponte/5922 on ubuntu: server started (service=MQTT, port=1883)

events.js:72 throw er; // Unhandled 'error' event ^ Error: listen EADDRINUSE at errnoException (net.js:904:11) at Server._listen2 (net.js:1042:14) at listen (net.js:1064:10) at Server.listen (net.js:1138:5) at new HTTP (/usr/local/lib/node_modules/ponte/lib/http.js:42:15) at Object.HTTP as factory at /usr/local/lib/node_modules/ponte/lib/ponte.js:39:9 at iterate (/usr/local/lib/node_modules/ponte/node_modules/async/lib/async.js:142:13) at /usr/local/lib/node_modules/ponte/node_modules/async/lib/async.js:153:25 at /usr/local/lib/node_modules/ponte/lib/ponte.js:41:7

To change http server port number i created a basic.js file as follows

var ponte = require("../lib/ponte"); var opts = { logger: { level: 'info' }, http: { port: 3030 // tcp }, mqtt: { port: 3001 // tcp }, coap: { port: 3000 // udp }, persistence: { type: 'level', path: './db' } }; var server = ponte(opts);

server.on("updated", function(resource, buffer) { console.log("Resource Updated", resource, buffer.toString()); });

Now the server is running and giving message on console as {"name":"ponte","hostname":"ubuntu","pid":2864,"service":"MQTT","level":30,"port":3001,"msg":"server started","time":"2014-05-07T06:49:14.876Z","v":0} {"name":"ponte","hostname":"ubuntu","pid":2864,"service":"HTTP","level":30,"port":3030,"msg":"server started","time":"2014-05-07T06:49:14.925Z","v":0} {"name":"ponte","hostname":"ubuntu","pid":2864,"service":"CoAP","level":30,"port":3000,"msg":"server started","time":"2014-05-07T06:49:14.927Z","v":0}

after that i created http and mqtt clients. am able to receive messages between similar clients like http to http and mqtt to mqtt but am not receiving message b/w different types of clients like http to mqtt or coap to http.

mcollina commented 10 years ago
[2014-05-07T08:52:21.619Z] INFO: ponte/5922 on ubuntu: server started (service=MQTT, port=1883)
events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at errnoException (net.js:904:11)
at Server._listen2 (net.js:1042:14)
at listen (net.js:1064:10)
at Server.listen (net.js:1138:5)
at new HTTP (/usr/local/lib/node_modules/ponte/lib/http.js:42:15)
at Object.HTTP as factory
at /usr/local/lib/node_modules/ponte/lib/ponte.js:39:9
at iterate (/usr/local/lib/node_modules/ponte/node_modules/async/lib/async.js:142:13)
at /usr/local/lib/node_modules/ponte/node_modules/async/lib/async.js:153:25
at /usr/local/lib/node_modules/ponte/lib/ponte.js:41:7

That means you have already another MQTT broker on your machine, e.g. Mosquitto or RabbitMQ.

Now the server is running and giving message on console as {"name":"ponte","hostname":"ubuntu","pid":2864,"service":"MQTT","level":30,"port":3001,"msg":"server started","time":"2014-05-07T06:49:14.876Z","v":0} {"name":"ponte","hostname":"ubuntu","pid":2864,"service":"HTTP","level":30,"port":3030,"msg":"server started","time":"2014-05-07T06:49:14.925Z","v":0} {"name":"ponte","hostname":"ubuntu","pid":2864,"service":"CoAP","level":30,"port":3000,"msg":"server started","time":"2014-05-07T06:49:14.927Z","v":0} after that i created http and mqtt clients. am able to receive messages between similar clients like http to http and mqtt to mqtt but am not receiving message b/w different types of clients like http to mqtt or coap to http.

Are you specifying the correct ports for MQTT, HTTP or CoAP?

chpradeep commented 10 years ago

I am specifying the same port numbers i used to run server

PONTE SERVER

sh@ubuntu:/home/PonteSetup/node_modules/ponte/examples$ sudo node basic. s {"name":"ponte","hostname":"ubuntu","pid":3471,"service":"MQTT","level":30,"port":3001,"msg":"server started","time":"2014-05-08T05:40:45.939Z","v":0} {"name":"ponte","hostname":"ubuntu","pid":3471,"service":"HTTP","level":30,"port":3030,"msg":"server started","time":"2014-05-08T05:40:45.974Z","v":0} {"name":"ponte","hostname":"ubuntu","pid":3471,"service":"CoAP","level":30,"port":3000,"msg":"server started","time":"2014-05-08T05:40:45.975Z","v":0}

(after posting a message from http client) {"name":"ponte","hostname":"ubuntu","pid":3471,"service":"HTTP","level":30,"req":{"method":"PUT","url":"/resources/hello","headers":{"user-agent":"curl/7.29.0","host":"localhost:3030","accept":"/","content-length":"7","content-type":"application/x-www-form-urlencoded"},"remoteAddress":"127.0.0.1","remotePort":55159},"msg":"start","time":"2014-05-08T05:40:55.042Z","v":0} Resource Updated /hello testing

(after subscribe a mosquitto client) {"name":"ponte","hostname":"ubuntu","pid":3471,"service":"MQTT","client":"mosqsub/3486-ubuntu","level":30,"msg":"client connected","time":"2014-05-08T05:41:34.315Z","v":0} {"name":"ponte","hostname":"ubuntu","pid":3471,"service":"MQTT","client":"mosqsub/3486-ubuntu","level":30,"topic":"hello","qos":0,"msg":"subscribed to topic","time":"2014-05-08T05:41:34.325Z","v":0} {"name":"ponte","hostname":"ubuntu","pid":3471,"service":"MQTT","client":"mosqsub/3486-ubuntu","level":30,"topic":"hello","msg":"delivering message","time":"2014-05-08T05:41:34.338Z","v":0}

(after posting a message from http client) {"name":"ponte","hostname":"ubuntu","pid":3471,"service":"HTTP","level":30,"req":{"method":"PUT","url":"/resources/hello","headers":{"user-agent":"curl/7.29.0","host":"localhost:3030","accept":"/","content-length":"7","content-type":"application/x-www-form-urlencoded"},"remoteAddress":"127.0.0.1","remotePort":55163},"msg":"start","time":"2014-05-08T05:42:18.946Z","v":0} Resource Updated /hello message

HTTP CLIENT

sh@ubuntu:~$ sudo curl -X PUT -d 'testing' http://localhost:3030/resources/hello sh@ubuntu:~$ sudo curl -X PUT -d 'message' http://localhost:3030/resources/hello

MOSQUITTO SUBSCRIBER

sh@ubuntu:~$ sudo mosquitto_sub -t "hello" -v -p 3001 (but no message am receiving here)

mcollina commented 10 years ago

Please update ponte to 0.0.8, and follow the development at http://github.com/eclipse/ponte.

arun4san commented 10 years ago

I have tried this examples it's not working.please guide me step by step how to do?

mcollina commented 10 years ago

What version of Ponte are you using? The develpment was moved at http://github.com/eclipse/ponte. Please open an issue there, and try the examples showed there.

arun4san commented 10 years ago

I have downloaded the source from githup and i have installed the essential npm modules also.Publish from HTTP its working once i try to Subscribe using mosquitto_sub its not working.

arun4san commented 10 years ago

first i have started my basic.js file and in browser i hit the url of http server.after try to Subscribe using mosquitto_sub in terminal its not Subscribing message.any thing i did wrong here..