{"id":15493283,"url":"https://github.com/0x171-0/iot-device-simulator","last_synced_at":"2026-05-06T19:32:52.499Z","repository":{"id":57677172,"uuid":"488226293","full_name":"0x171-0/iot-device-simulator","owner":"0x171-0","description":"Auto random custom data generator \u0026 publisher for MQTT broker","archived":false,"fork":false,"pushed_at":"2022-05-15T07:42:52.000Z","size":978,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-23T16:11:44.572Z","etag":null,"topics":["iot","javascript","mqtt","nodejs","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/iot-device-simulator","language":"TypeScript","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/0x171-0.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}},"created_at":"2022-05-03T13:42:53.000Z","updated_at":"2024-11-02T02:45:31.000Z","dependencies_parsed_at":"2022-08-24T19:41:02.286Z","dependency_job_id":null,"html_url":"https://github.com/0x171-0/iot-device-simulator","commit_stats":null,"previous_names":["masoncalmandcode/iot-device-simulator"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/0x171-0/iot-device-simulator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0x171-0%2Fiot-device-simulator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0x171-0%2Fiot-device-simulator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0x171-0%2Fiot-device-simulator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0x171-0%2Fiot-device-simulator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/0x171-0","download_url":"https://codeload.github.com/0x171-0/iot-device-simulator/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0x171-0%2Fiot-device-simulator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32444945,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T20:22:27.477Z","status":"ssl_error","status_checked_at":"2026-04-29T20:22:26.507Z","response_time":110,"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","javascript","mqtt","nodejs","typescript"],"created_at":"2024-10-02T08:05:17.022Z","updated_at":"2026-04-29T21:31:35.522Z","avatar_url":"https://github.com/0x171-0.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# IoT Device Simulator\n\n**IoT device simulator to auto-generate random data in the customized format and publish to MQTT broker.**\n\nFeedback, issues, and pull requests are always appreciated :)\n\n\u003c!-- [![Coverage Status](https://coveralls.io/repos/github/masonCalmAndCode/iot-device-simulator/badge.svg?branch=master\u0026service=github)](https://github.com/masonCalmAndCode/iot-device-simulator) --\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://www.npmjs.com/package/iot-device-simulator\"\u003e\n    \u003cimg alt=\"\" src=\"https://img.shields.io/npm/dt/iot-device-simulator.svg?style=flat-square\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/iot-device-simulator\"\u003e\n    \u003cimg alt=\"\" src=\"https://img.shields.io/npm/v/iot-device-simulator.svg?style=flat-square\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/iot-device-simulator\"\u003e\n    \u003cimg alt=\"\" src=\"https://api.codeclimate.com/v1/badges/9ad73ee4890101f8ac38/maintainability\"\u003e\n\u003c/a\u003e\n\u003c/p\u003e\n\n\u003c!-- [![license](https://img.shields.io/github/license/masonCalmAndCode/iot-device-simulator)](https://github.com/masonCalmAndCode/iot-device-simulator) --\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"https://media.giphy.com/media/n6mEMqAuYOQ8l8qcEE/giphy.gif\" width=\"1000\"/\u003e\n\u003c/div\u003e\n\n## Installation\n\nRun `npm install iot-device-simulator --save` to download the library.\n\n## Features\n\n- Easily generate dummy data from a customized format\n- Publish customized report to MQTT broker in interval time\n- Easily change the state of the device simulator to generate different data to represent the different scenario\n\n## **Module Schema**\n\n![](uml.png)\n\n## Import Modules\n\n```typescript\n// Approach 1\nimport simulator from 'iot-device-simulator';\n// Approach 2\nimport {\n  createConnectionToBroker,\n  createDevice,\n  createDeviceType,\n} from 'iot-device-simulator';\n```\n\n## Usage\n\n### 1. **Create Connection**\n\n```typescript\nimport { createConnectionToBroker } from 'iot-device-simulator';\nconst connection = createConnectionToBroker({\n  url: 'http://your.host.and.port:1234',\n  clientId: 'your_clientId',\n  username: 'your_name',\n  password: 'your_password',\n});\n```\n\n### 2. **Create Device Type And States**\n\n- A device type has multiple states.\n- Every state has a customized report format.\n- Dummy data will generate randomly according to the format of the state.\n- [How to define format of state?](#state-format-column-definition)\n\n```typescript\nconst lum = createDeviceType('luminance_meter');\n\n// Create State With Custimised Report Format\nconst lumFormat = [\n  { id: 'version', value: ['v1', 'v2'] },\n  { id: 'voltage', value: { max: 100, min: 0, digit: 0 } },\n  { id: 'module', value: 1.1 },\n];\n\n// Every state has it's own report format\nlum.addState({\n  name: 'dark',\n  payload: [\n    ...lumFormat,\n    { id: 'brightness', value: { max: 20, min: 0, digit: 1 } }, // different states may return different lum\n  ],\n});\nlum.addState({\n  name: 'dusk',\n  payload: [\n    ...lumFormat,\n    { id: 'brightness', value: { max: 40, min: 20, digit: 1 } },\n  ],\n});\nlum.addState({\n  name: 'day',\n  payload: [\n    ...lumFormat,\n    { id: 'brightness', value: { max: 100, min: 40, digit: 1 } },\n  ],\n});\n```\n\n### 3.**Create Device Instance From Device Type**\n\n```typescript\nconst lumBot = createDevice({\n  type: lum,\n  state: 'day',\n  connection,\n  topic: '$device/IOTAWESOME/report',\n});\n// change state to change report\nlumBot.setState('dusk');\n// change interval to change time to send report to broker every interval seconds\nlumBot.setInterval(2000);\n// change topic to report\nlumBot.setTopic('$device/IOTAWESOME/report');\n// change state of device, when active constantly send report, when inactive stop to report\nlumBot.toggleIsActive();\n```\n\n### 4. Subscribe Topic To Trigger State Changing\n\n- examples\n  - change the state to 'dark', when get topic `$device/IOTAWESOME/cmd` publish message, and the payload index 0 , 'value' key's value equals to 10\n\n```typescript\nlumBot.addSubTopic({\n  topic: '$device/IOTAWESOME/cmd', // topic to sbscribe\n  trigger: { key: '0.value', value: 10, state: 'dark' },\n  // key to get value from key and the expected state\n  // key will be split by '.' and for the keys array to get the value. like example below:\n  // example payload =\u003e [{ id: 'brightness', value: 10 }];\n  // payload[0]['value'] = 10\n});\n```\n\n## State Format Column Definition\n\nThere are two categories of type 'value' and 'reference'. 'value' type is the base case of the column, and the reference type is the combination of the base case. Please see the examples below.\n\n_ps: If you want to test or get dummy data simply from the format can use the '**generateDataFromFormat**' function_\n\n### **1. Value Type column**\n\nValue type columns are the base case of a column.\nIf you nested the base case in the reference type column, it will recursively loop into it and generate dummy data until the end.\n\n1. **boolean**\n\n1. **number**\n\n1. **string**\n\n```typescript\nimport { generateDataFromFormat } from 'iot-device-simulator';\nconsole.log(generateDataFromFormat(true)); // true\nconsole.log(generateDataFromFormat(123)); // 123\nconsole.log(generateDataFromFormat('IoT')); // IoT\n```\n\n### 2. Reference Type column\\*\\*\n\nReference type columns are a combination of base case columns. The function for generating data will recursively loop into and generate dummy data until hit a base case end.\n\n- **range**\n  - An object with max, min, and digit\n  - Return a random number with specified decimals equal to the digit\n\n```typescript\nconst result = generateDataFromFormat({ max: 100, min: 0, digit: 2 });\nconsole.log(result); // number 0~100 with 2 decimals, ex: 29.03\n```\n\n- **tuple**\n  - Combined multiple base columns and reference columns into an array\n  - Return element in the array randomly\n\n```typescript\nconst result = generateDataFromFormat([\n  8, // number\n  { max: 100, min: 0, digit: 0 }, // range\n  'voltage', // string\n  {\n    // object\n    id: 'voltage',\n    value: { max: 10, min: 0, digit: 0 },\n  },\n]);\nconsole.log(result); // [ 8, 52, 'voltage', { id: 'voltage', value: 10 } ]\n```\n\n- **enum**\n  - Combined multiple base columns into array\n  - Return element in the array randomly\n\n```typescript\nconst result = generateDataFromFormat([\n  0, // number\n  'v1.0', // string\n  123, // number\n]);\nconsole.log(result); // 0 or 'v1.0' or 123\n```\n\n- **object**\n  - object with keys storing a value of value or reference type of columns\n  - return an object of recursively generated data\n\n```typescript\nconst result = generateDataFromFormat({\n  id: 'axisZ', // string\n  value: 6.6, // number\n  range: { max: 100, min: 0, digit: 0 }, // range\n  // or any other types in value even object itself, nested combination is allowed\n});\nconsole.log(result); // { id: 'axisZ', value: 6.6, range: 56 }\n```\n\n## Test\n\nTo start a test, run the following command:\n\n`npm run test`\n\n## License\n\n© Mason Yu (masonCalmAndCode), 2022-NOW\n\nReleased under the [MIT License](https://github.com/masonCalmAndCode/iot-device-simulator/blob/main/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0x171-0%2Fiot-device-simulator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F0x171-0%2Fiot-device-simulator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0x171-0%2Fiot-device-simulator/lists"}