Giter VIP home page Giter VIP logo

Comments (14)

golfvert avatar golfvert commented on July 4, 2024 1

Running same pkg version (5.8.1) but node 20.11.1.
Anyway, not related to this great tool. So, I'll close this.
Thanks for great help. Much appreciated.

from mqttx.

golfvert avatar golfvert commented on July 4, 2024 1

My questions were answered :)

from mqttx.

ysfscream avatar ysfscream commented on July 4, 2024

@golfvert Hi. Thanks for your use.

Currently, it's not possible to dynamically add a built-in test scenario at runtime within mqttx-cli. We might support this functionality in the future. For the time being, here's the recommended workaround to include your custom test scenario:

  1. Download the source code and add a TypeScript (.ts) file to the cli/scenarios folder, mimicking the format of the existing built-in scenario files.

Then, proceed with either of the following steps based on your needs:

  1. For local development and packaging:
    • Ensure Node.js and Yarn are installed.
    • Run yarn build in the project root to compile TypeScript files.
    • If needed, install the pkg package and use pkg . to generate an executable binary found in the release folder.

Or,

  1. For Docker deployment:
    • Run docker build -t mqttx-cli . to create a Docker image with your custom scenario, and run docker run -it mqttx-cli
image image

from mqttx.

golfvert avatar golfvert commented on July 4, 2024

Hi,
Thank you for your answer. By looking into the code, I saw that it wasn't dynamic.
However, even after done the yarn build I can't find the new scenario. Do I need to package it ?
At runtime, which directory is used to find the scenario ?
I can't see it in node_modules/mqttx-cli/dist/src/scenarios/
Not sure why, though...

from mqttx.

ysfscream avatar ysfscream commented on July 4, 2024

Hi,

It's best not to modify anything directly in `node_modules/mqttx-cli. Instead, please follow these steps:

  1. Clone the MQTTX repo and make changes in the cloned directory, not in node_modules.
  2. Add your scenario in the cli/scenarios folder.
  3. Build the project with yarn build or npm run build in the root directory of your cloned project.

This approach ensures your changes are saved and tracked correctly.

from mqttx.

golfvert avatar golfvert commented on July 4, 2024

This is what I have done... I have added my new scenario in my cloned directory is cli/src/scenario. I run yarn build. All seems to be fine:

laptop-2:cli me$ ls -l src/scenarios/
total 40
-rwxr-xr-x@ 1 me  staff  2195 Feb 29 03:53 IEM.ts
-rwxr-xr-x@ 1 me  staff  2620 Feb 29 03:53 smart_home.ts
-rwxr-xr-x@ 1 me  staff  3921 Feb 29 03:53 tesla.ts
-rwxr-xr-x@ 1 me  staff  3805 Feb 29 03:53 weather.ts
-rwxr-xr-x@ 1 me  staff  1068 Mar  3 19:49 test.ts
laptop-2:cli me$ touch src/scenarios/test.ts
laptop-2:cli me$ yarn build
yarn run v1.22.21
$ tsc
✨  Done in 2.12s.
laptop-2:cli me$ ls-l dist/src/scenarios/
-bash: ls-l: command not found
laptop-2:cli me$ ls -l dist/src/scenarios/
total 56
-rw-r--r--  1 me  staff  2944 Mar  3 15:18 IEM.js
-rw-r--r--  1 me  staff  2839 Mar  3 15:18 smart_home.js
-rw-r--r--  1 me  staff  4424 Mar  3 15:18 tesla.js
-rw-r--r--  1 me  staff  4788 Mar  3 15:18 weather.js
-rw-r--r--  1 me  staff  1762 Mar  3 19:49 test.js
laptop-2:cli me$ ./node_modules/.bin/mqttx ls --scenarios
You can use any of the above scenario names as a parameter to run the scenario.
┌───────────────┬──────────────────────────────────────────────────────────────────────────────────────────────┐
│ Scenario Name │ Description                                                                                  │
├───────────────┼──────────────────────────────────────────────────────────────────────────────────────────────┤
│ IEM           │ Simulation to generate Industrial Energy Monitoring data.                                    │
├───────────────┼──────────────────────────────────────────────────────────────────────────────────────────────┤
│ smart_home    │ Simulation to generate Smart Home data.                                                      │
├───────────────┼──────────────────────────────────────────────────────────────────────────────────────────────┤
│ tesla         │ Simulation to generate Tesla's data, reference form https://github.com/adriankumpf/teslamate │
├───────────────┼──────────────────────────────────────────────────────────────────────────────────────────────┤
│ weather       │ Simulation to generate advanced weather station's data.                                      │
└───────────────┴──────────────────────────────────────────────────────────────────────────────────────────────┘
laptop-2:cli me$

from mqttx.

ysfscream avatar ysfscream commented on July 4, 2024

To run the ./node_modules/.bin/mqttx ls --scenarios command, make sure to first run yarn dev in the development environment.

from mqttx.

golfvert avatar golfvert commented on July 4, 2024

I am totally ignorant on yarn... Sorry.

yarn dev gives me this:

[11:06:15 AM] Starting compilation in watch mode...

[11:06:16 AM] Found 0 errors. Watching for file changes.

And nothing else.

This is my lack of knowledge on yarn that prevent this to work, I guess...

from mqttx.

golfvert avatar golfvert commented on July 4, 2024

And running

laptop-2:cli remy$ pkg .
> [email protected]
> Warning Failed to make bytecode node16-x64 for file /snapshot/cli/node_modules/axios/index.js
> Warning Failed to make bytecode node16-x64 for file /snapshot/cli/node_modules/axios/lib/axios.js
> Warning Failed to make bytecode node16-x64 for file /snapshot/cli/node_modules/axios/lib/utils.js
> Warning Failed to make bytecode node16-x64 for file /snapshot/cli/node_modules/axios/lib/helpers/bind.js
...

fails.

which is apparently a known bug... axios/axios#5650

:(

from mqttx.

golfvert avatar golfvert commented on July 4, 2024

Docker build works though:

docker run -it mqttx-cli
/app # mqttx ls --scenarios
You can use any of the above scenario names as a parameter to run the scenario.
┌───────────────┬──────────────────────────────────────────────────────────────────────────────────────────────┐
│ Scenario Name │ Description                                                                                  │
├───────────────┼──────────────────────────────────────────────────────────────────────────────────────────────┤
│ IEM           │ Simulation to generate Industrial Energy Monitoring data.                                    │
├───────────────┼──────────────────────────────────────────────────────────────────────────────────────────────┤
│ smart_home    │ Simulation to generate Smart Home data.                                                      │
├───────────────┼──────────────────────────────────────────────────────────────────────────────────────────────┤
│ tesla         │ Simulation to generate Tesla's data, reference form https://github.com/adriankumpf/teslamate │
├───────────────┼──────────────────────────────────────────────────────────────────────────────────────────────┤
│ weather       │ Simulation to generate advanced weather station's data.                                      │
├───────────────┼──────────────────────────────────────────────────────────────────────────────────────────────┤
│ test          │ test                                          │
└───────────────┴──────────────────────────────────────────────────────────────────────────────────────────────┘
/app #

I guess I'll do that...

from mqttx.

ysfscream avatar ysfscream commented on July 4, 2024

Great to see you've successfully run your custom scenario in Docker!

You need to run yarn dev to initiate the development environment for local development. Afterward, you should use the command from the project's root directory, like node ./bin/index.js conn -h broker.emqx.io, instead of using anything from node_modules. This ensures your custom scenario is correctly recognized and executed.

Hope this helps solve your issue!

from mqttx.

golfvert avatar golfvert commented on July 4, 2024

Thanks for the good advices. Super helpful.
Any comment on the pkg . issue above ?

from mqttx.

ysfscream avatar ysfscream commented on July 4, 2024

I have no idea about this, but I can share my versions about Node.js and pkg.

pkg -v
5.8.1

node -v
v16.14.2

Hope helpful to you.

from mqttx.

ysfscream avatar ysfscream commented on July 4, 2024

Thanks for using it. I will solve this issue.

from mqttx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.