{"id":21585178,"url":"https://github.com/conectric/nodemqtt","last_synced_at":"2026-04-13T11:01:51.243Z","repository":{"id":93434739,"uuid":"88890916","full_name":"Conectric/nodemqtt","owner":"Conectric","description":"Quick Demo using MQTT module in Node.js","archived":false,"fork":false,"pushed_at":"2018-01-02T18:40:33.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-01T20:56:46.837Z","etag":null,"topics":["iot","mqtt","mqtt-protocol","nodejs"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Conectric.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-20T17:09:44.000Z","updated_at":"2017-04-20T17:20:50.000Z","dependencies_parsed_at":"2023-03-08T13:30:39.520Z","dependency_job_id":null,"html_url":"https://github.com/Conectric/nodemqtt","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Conectric/nodemqtt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Conectric%2Fnodemqtt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Conectric%2Fnodemqtt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Conectric%2Fnodemqtt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Conectric%2Fnodemqtt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Conectric","download_url":"https://codeload.github.com/Conectric/nodemqtt/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Conectric%2Fnodemqtt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31749763,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-13T09:16:15.125Z","status":"ssl_error","status_checked_at":"2026-04-13T09:16:05.023Z","response_time":93,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["iot","mqtt","mqtt-protocol","nodejs"],"created_at":"2024-11-24T15:09:19.577Z","updated_at":"2026-04-13T11:01:51.226Z","avatar_url":"https://github.com/Conectric.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Node MQTT Demo\n\nThis is a very basic demo of using the [MQTT package](https://www.npmjs.com/package/mqtt) with Node.js to send messages between a set of fake sensors, and a server.\n\nThis demo uses the free [HiveMQ MQTT broker](http://www.mqtt-dashboard.com/).  You can read more about how MQTT works [here](http://www.hivemq.com/blog/mqtt-essentials-part-1-introducing-mqtt).\n\nAlternatively you could install your own MQTT broker, for example [Mosquitto](https://test.mosquitto.org/).\n\n## Setup\n\n* Install [Node.js](https://nodejs.org)\n* Clone this repo, then:\n\n```\ncd nodemqtt\nnpm install\n```\n\n## Starting the Components\n\nThere are two components, the \"server\" (see `server.js`), and the \"sensor\" (see `sensor.js`).  You should start one server and one or more sensor instances.\n\n### Starting the Server\n\nStart the server first, with:\n\n```\nnpm start\n```\n\nIf all goes well it should connect to the MQTT broker, and output something similar to:\n\n```\n$ npm start\n\n\u003e nodemqtt@0.0.1 start /Users/simon/source/projects/nodemqtt\n\u003e node server.js\n\nServer is waiting for messages.\n```\n\nNothing else will happen until you start at least one sensor.\n\n### Starting Sensor(s)\n\nEach sensor has an ID number.  The one provided has ID 0 and is configured in `package.json`:\n\n```\n\"scripts\": {\n  \"sensor\": \"node sensor.js 0\"\n},\n```\n\nTo start this, simply use:\n\n```\nnpm run sensor\n```\n\nOnce started the sensor should push MQTT messages into the broker every 5 seconds, each message containing the sensor ID number and the current date and time.  If running successfully, output from the sensor should look like:\n\n```\n$ npm run sensor\n\n\u003e nodemqtt@0.0.1 sensor /Users/simon/source/projects/nodemqtt\n\u003e node sensor.js 0\n\nStarted sensor 0\nSending data: 0|Thu Apr 20 2017 09:55:02 GMT-0700 (PDT)\nSending data: 0|Thu Apr 20 2017 09:55:07 GMT-0700 (PDT)\n```\n\nAnd if the server is running, it should start receiving messages and logging those:\n\n```\n$ npm start\n\n\u003e nodemqtt@0.0.1 start /Users/simon/source/projects/nodemqtt\n\u003e node server.js\n\nServer is waiting for messages.\nRegistering sensor ID: 0\nReceived sensor message: 0|Thu Apr 20 2017 09:55:02 GMT-0700 (PDT)\nReceived sensor message: 0|Thu Apr 20 2017 09:55:07 GMT-0700 (PDT)\nReceived sensor message: 0|Thu Apr 20 2017 09:55:12 GMT-0700 (PDT)\nReceived sensor message: 0|Thu Apr 20 2017 09:55:17 GMT-0700 (PDT)\nReceived sensor message: 0|Thu Apr 20 2017 09:55:22 GMT-0700 (PDT)\nReceived sensor message: 0|Thu Apr 20 2017 09:55:27 GMT-0700 (PDT)\n```\n\nTo start more than one instance of the sensor, add more lines to the `scripts` section of `package.json` and invoke `npm` to run them e.g.:\n\n```\n\"scripts\": {\n  \"sensor\": \"node sensor.js 0\",\n  \"sensor1\": \"node sensor.js 1\"\n},\n```\n\nThen start sensor1:\n\n```\nnpm run sensor1\n```\n\nThe server should then start reporting output from both sensors:\n\n```\nReceived sensor message: 0|Thu Apr 20 2017 09:58:22 GMT-0700 (PDT)\nRegistering sensor ID: 1\nReceived sensor message: 0|Thu Apr 20 2017 09:58:27 GMT-0700 (PDT)\nReceived sensor message: 1|Thu Apr 20 2017 09:58:29 GMT-0700 (PDT)\nReceived sensor message: 0|Thu Apr 20 2017 09:58:32 GMT-0700 (PDT)\nReceived sensor message: 1|Thu Apr 20 2017 09:58:34 GMT-0700 (PDT)\n```\n\n## Configuration\n\nBasic configuration information is contained in `common.js` which exposes an object containing topic names and broker URL:\n\n```\nmodule.exports = {\n  MQTT_BROKER: 'broker.hivemq.com',\n  REGISTER_TOPIC: 'sensor/register',\n  DATA_TOPIC: 'sensor/data'\n};\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconectric%2Fnodemqtt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fconectric%2Fnodemqtt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconectric%2Fnodemqtt/lists"}