Provides a mock Ambi client that emulates real sensor hardware such as an Edge client

Overview

ambi_mock_client

Provides a mock Ambi client that emulates real sensor hardware such as an Edge client.

Usage

You must have Rust installed to build ambi_mock_client. You can find documentation on installing Rust here.

You will also need a local copy of Ambi running ( default port 4000 ).

Using cargo run

cargo run">
> cargo build
> cargo run

Sending POST request to http://localhost:4000/api/readings/add as JSON: {"tempurature":"19.2","humidity":"87.7","pressure":"1074","dust_concentration":"415","air_purity":"DANGEROUS"}
Response: Ok(
    Response {
        url: Url {
            scheme: "http",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: Some(
                Domain(
                    "localhost",
                ),
            ),
            port: Some(
                4000,
            ),
            path: "/api/readings/add",
            query: None,
            fragment: None,
        },
        status: 200,
        headers: {
            "cache-control": "max-age=0, private, must-revalidate",
            "content-length": "60",
            "content-type": "application/json; charset=utf-8",
            "date": "Sat, 22 Jan 2022 19:25:14 GMT",
            "server": "Cowboy",
            "x-request-id": "FsyuNssWKjhYHbUAAAAj",
        },
    },
)

# Or just

> cargo run

As an executable binary

> cargo build
> ./target/debug/ambi_mock_client

Sending POST request to http://localhost:4000/api/readings/add as JSON: {"tempurature":"28.8","humidity":"85.2","pressure":"964","dust_concentration":"930","air_purity":"DANGEROUS"}
Response: Ok(
    Response {
        url: Url {
            scheme: "http",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: Some(
                Domain(
                    "localhost",
                ),
            ),
            port: Some(
                4000,
            ),
            path: "/api/readings/add",
            query: None,
            fragment: None,
        },
        status: 200,
        headers: {
            "cache-control": "max-age=0, private, must-revalidate",
            "content-length": "60",
            "content-type": "application/json; charset=utf-8",
            "date": "Sat, 22 Jan 2022 19:28:08 GMT",
            "server": "Cowboy",
            "x-request-id": "FsyuX1U1NOj9m7IAAABB",
        },
    },
)
Comments
  • Make use of the debug CLI flag and refactor app layout

    Make use of the debug CLI flag and refactor app layout

    Makes use of the newly added debug CLI flag (-d or --debug) for HTTP request response status and error printing.

    NOTE: this also moves most of the application logic into lib.rs and out from main.rs which follows a standard Rust application logic separation pattern.

    Example output

    Success, with debugging off:

    $ target/debug/ambi_mock_client
    
    cli: Cli { debug: false }
    
    Sending POST request to http://localhost:4000/api/readings/add as JSON: {"temperature":"28.8","humidity":"72.9","pressure":"1059","dust_concentration":"919","air_purity":"High Pollution"}
    Response from Ambi backend: "200
    

    Success, with debugging on:

    $ target/debug/ambi_mock_client -d
    
    cli: Cli { debug: true }
    
    Sending POST request to http://localhost:4000/api/readings/add as JSON: {"temperature":"25.4","humidity":"61.8","pressure":"1002","dust_concentration":"842","air_purity":"High Pollution"}
    Response from Ambi backend: Response {
        url: Url {
            scheme: "http",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: Some(
                Domain(
                    "localhost",
                ),
            ),
            port: Some(
                4000,
            ),
            path: "/api/readings/add",
            query: None,
            fragment: None,
        },
        status: 200,
        headers: {
            "cache-control": "max-age=0, private, must-revalidate",
            "content-length": "60",
            "content-type": "application/json; charset=utf-8",
            "date": "Sun, 03 Apr 2022 21:18:34 GMT",
            "server": "Cowboy",
            "x-request-id": "FuJ_mmWyDZ045GkAAAAF",
        },
    }
    

    Error, with debugging off:

    $ target/debug/ambi_mock_client
    
    cli: Cli { debug: false }
    
    Sending POST request to http://localhost:4000/api/readings/add as JSON: {"temperature":"26.8","humidity":"47.8","pressure":"1087","dust_concentration":"780","air_purity":"High Pollution"}
    Response error from Ambi backend: request error
    

    Error, with debugging on:

    $ target/debug/ambi_mock_client -d
    
    cli: Cli { debug: true }
    
    Sending POST request to http://localhost:4000/api/readings/add as JSON: {"temperature":"33.0","humidity":"53.1","pressure":"957","dust_concentration":"738","air_purity":"High Pollution"}
    Response error from Ambi backend: reqwest::Error { kind: Request, url: Url { scheme: "http", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("localhost")), port: Some(4000), path: "/api/readings/add", query: None, fragment: None }, source: hyper::Error(Connect, ConnectError("tcp connect error", Os { code: 61, kind: ConnectionRefused, message: "Connection refused" })) }
    
    enhancement 
    opened by jhodapp 5
  • Mock client sends invalid JSON POST request to ambi backend for sensor readings

    Mock client sends invalid JSON POST request to ambi backend for sensor readings

    Ambi backend interprets JSON here

    Currently, the mock client sends an invalid JSON request, which ambi receives and is unable to parse. This results in an empty parameters field on the backend.

    See this issue for an example of the ambi response

    opened by wumbabum 4
  • Added foundation of command line interface argument/flag parsing/handling

    Added foundation of command line interface argument/flag parsing/handling

    Added the use of the crate clap for command line interface argument/flag parsing.

    Clap reference

    Provides -d|--debug, -V|--version and -h|--help with this changeset.

    Refer to the ambi_mock_client CLI design document for more background info.

    Also sets the foundation for separation of application logic now being in lib.rs instead of everything being in main.rs. See the Rust book section 12.3 for more info.

    Example output

    $ ambi_mock_client --help
    Ambi Mock Client 0.1.0
    Rust Never Sleeps community (https://github.com/Jim-Hodapp-Coaching/)
    This application emulates a real set of hardware sensors that can report on environmental conditions
    such as temperature, pressure, humidity, etc.
    
    USAGE:
        ambi_mock_client [OPTIONS]
    
    OPTIONS:
        -d, --debug
                Turns verbose console debug output on
    
        -h, --help
                Print help information
    
        -V, --version
                Print version information
    

    or setting verbose debug output on:

    $ ambi_mock_client -d
    Debug mode is now *on*
    
    cli: Cli { debug: true }
    
    Sending POST request to http://localhost:4000/api/readings/add as JSON: {"temperature":"24.2","humidity":"70.1","pressure":"960","dust_concentration":"999","air_purity":"High Pollution"}
    Response: Ok(
        Response {
            url: Url {
                scheme: "http",
                cannot_be_a_base: false,
                username: "",
                password: None,
                host: Some(
                    Domain(
                        "localhost",
                    ),
                ),
                port: Some(
                    4000,
                ),
                path: "/api/readings/add",
                query: None,
                fragment: None,
            },
            status: 200,
            headers: {
                "cache-control": "max-age=0, private, must-revalidate",
                "content-length": "60",
                "content-type": "application/json; charset=utf-8",
                "date": "Thu, 31 Mar 2022 20:17:33 GMT",
                "server": "Cowboy",
                "x-request-id": "FuF_EewOgIHT5BkAAEfn",
            },
        },
    )
    

    Closes #5

    enhancement 
    opened by jhodapp 2
  • Add stronger types

    Add stronger types

    I added stronger typing to the Reading struct. The types used were mostly dictated by the Rust to Postgresql type mapping that Diesel implements. I removed some test that were no longer valid. I didn't replace any since I felt the type system was already doing basically the same sort of checks. If you have any suggestions on additional tests that you think should be added then let me know.

    This has been tested against ambi (Elixir) and the initial implementation of ambi-rs that is still in PR. It could successfully post readings to both.

    enhancement 
    opened by naconnors 1
  • Add pre-commit code formatting

    Add pre-commit code formatting

    This change adds a new pre-commit hook that will run cargo fmt and add the changed files to the commit. This ensures that all of the code in the repository meets our code quality standards, and removes the responsibility of running the fmt command from the author so that they are not forced to remember and reviewers do not need to ask for formatting updates. This also conveniently adds the updates to the commit containing the changed files so that the author does not need to do any squashing or fixing up later.

    To install the new commit hook in your local workspace, you can run ./scripts/create-git-hooks, which will set up a symlink to a hooks-wrapper script that can run any commit hook that we currently have or add in the future.

    build system 
    opened by Serneum 0
  • Split app logic and use debug flag for response output

    Split app logic and use debug flag for response output

    Makes use of the newly added debug CLI flag (-d or --debug) for HTTP request response status and error printing.

    NOTE: this also moves most of the application logic into lib.rs and out from main.rs which follows a standard Rust application logic separation pattern.

    Example output Success, with debugging off:

    $ target/debug/ambi_mock_client

    cli: Cli { debug: false }

    Sending POST request to http://localhost:4000/api/readings/add as JSON: {"temperature":"28.8","humidity":"72.9","pressure":"1059","dust_concentration":"919","air_purity":"High Pollution"} Response from Ambi backend: "200 Success, with debugging on:

    $ target/debug/ambi_mock_client -d

    cli: Cli { debug: true }

    Sending POST request to http://localhost:4000/api/readings/add as JSON: {"temperature":"25.4","humidity":"61.8","pressure":"1002","dust_concentration":"842","air_purity":"High Pollution"} Response from Ambi backend: Response { url: Url { scheme: "http", cannot_be_a_base: false, username: "", password: None, host: Some( Domain( "localhost", ), ), port: Some( 4000, ), path: "/api/readings/add", query: None, fragment: None, }, status: 200, headers: { "cache-control": "max-age=0, private, must-revalidate", "content-length": "60", "content-type": "application/json; charset=utf-8", "date": "Sun, 03 Apr 2022 21:18:34 GMT", "server": "Cowboy", "x-request-id": "FuJ_mmWyDZ045GkAAAAF", }, } Error, with debugging off:

    $ target/debug/ambi_mock_client

    cli: Cli { debug: false }

    Sending POST request to http://localhost:4000/api/readings/add as JSON: {"temperature":"26.8","humidity":"47.8","pressure":"1087","dust_concentration":"780","air_purity":"High Pollution"} Response error from Ambi backend: request error Error, with debugging on:

    $ target/debug/ambi_mock_client -d

    cli: Cli { debug: true }

    Sending POST request to http://localhost:4000/api/readings/add as JSON: {"temperature":"33.0","humidity":"53.1","pressure":"957","dust_concentration":"738","air_purity":"High Pollution"} Response error from Ambi backend: reqwest::Error { kind: Request, url: Url { scheme: "http", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("localhost")), port: Some(4000), path: "/api/readings/add", query: None, fragment: None }, source: hyper::Error(Connect, ConnectError("tcp connect error", Os { code: 61, kind: ConnectionRefused, message: "Connection refused" })) }

    Replaces #7

    enhancement 
    opened by jhodapp 0
  • Add basic command line interface to ambi_mock_client

    Add basic command line interface to ambi_mock_client

    Add the basic infrastructure necessary to have a command line interface (CLI) which will include:

    • -h: print basic command runtime interface information/options
    • -v: print ambi_mock_client's current version
    enhancement 
    opened by jhodapp 0
  • Update air purity to_string values to match expected values on ambi.

    Update air purity to_string values to match expected values on ambi.

    Updates Mock client to use a set of air purity values which correctly match expected values on ambi app. Previously, ambi app would give an error "no cond clause evaluated to a truthy value" when reading entries from the DB. These DB entries came from the mock client and were faulty due to mismatched error purity values.

    Correct entry values were taken from these lines in ambi: https://github.com/Jim-Hodapp-Coaching/ambi/blob/afcef37ed7593084ac4aa0ad19ac65bb02ffacfc/lib/ambi_web/live/reading_live.html.leex#L77-L86

    In Ambi mock client:

    Sending POST request to http://localhost:4000/api/readings/add as JSON: {"temperature":"24.2","humidity":"95.6","pressure":"1041","dust_concentration":"636","air_purity":"High Pollution"}
    

    *Note the proper capitalization of High Pollution

    In Ambi app

      Parameters: %{"air_purity" => "High Pollution", "dust_concentration" => "636", "humidity" => "95.6", "pressure" => "1041", "temperature" => "24.2"}
      Pipelines: [:api]
    [debug] QUERY OK db=2.4ms queue=0.7ms idle=631.8ms
    INSERT INTO "readings" ("air_purity","dust_concentration","humidity","pressure","temperature","inserted_at","updated_at") VALUES ($1,$2,$3,$4,$5,$6,$7) RETURNING "id" ["High Pollution", 636.0, 95.6, 1041, 24.2, ~N[2022-02-07 20:14:47], ~N[2022-02-07 20:14:47]]
    [debug] Added new reading to the DB
    [info] Sent 200 in 43ms
    
    opened by wumbabum 0
  • Fix deprecated warning

    Fix deprecated warning

    There is a deprecated warning that we should address at some point: warning: use of deprecated associated function clap::ArgMatches::is_present: Replaced with either ArgAction::SetTrue or ArgMatches::contains_id(...) --> src/lib.rs:33:16 | 33 | pub debug: bool, | ^^^^ | = note: #[warn(deprecated)] on by default warning: ambi_mock_client (lib) generated 1 warning

    opened by naconnors 0
  • Add concurrent requests

    Add concurrent requests

    Description

    This PR adds a -i, --int <INT> flag to the CLI for sending INT number of concurrent requests to Ambi at a time.

    caleb@calebs-MBP ambi_mock_client % ./target/debug/ambi_mock_client --help                      
    Ambi Mock Client 0.1.0
    Rust Never Sleeps community (https://github.com/Jim-Hodapp-Coaching/)
    This application emulates a real set of hardware sensors that can report on environmental conditions
    such as temperature, pressure, humidity, etc.
    
    USAGE:
        ambi_mock_client [OPTIONS]
    
    OPTIONS:
        -d, --debug
                Turns verbose console debug output on
    
        -h, --help
                Print help information
    
        -i, --int <INT>
                [default: 1]
    
        -V, --version
                Print version information
    
    caleb@calebs-MBP ambi_mock_client % ./target/debug/ambi_mock_client -i 15
    
    cli: Cli { debug: false, int: 15 }
    
    Sending POST request to http://localhost:4000/api/readings/add as JSON: {"temperature":"22.4","humidity":"58.2","pressure":"941","dust_concentration":"999","air_purity":"High Pollution"}
    Sending POST request to http://localhost:4000/api/readings/add as JSON: {"temperature":"34.0","humidity":"18.2","pressure":"992","dust_concentration":"327","air_purity":"High Pollution"}
    Sending POST request to http://localhost:4000/api/readings/add as JSON: {"temperature":"23.4","humidity":"66.5","pressure":"1014","dust_concentration":"986","air_purity":"High Pollution"}
    Sending POST request to http://localhost:4000/api/readings/add as JSON: {"temperature":"24.0","humidity":"41.3","pressure":"1054","dust_concentration":"709","air_purity":"High Pollution"}
    Sending POST request to http://localhost:4000/api/readings/add as JSON: {"temperature":"34.2","humidity":"99.7","pressure":"906","dust_concentration":"52","air_purity":"Fresh Air"}
    Sending POST request to http://localhost:4000/api/readings/add as JSON: {"temperature":"32.7","humidity":"41.4","pressure":"1026","dust_concentration":"598","air_purity":"High Pollution"}
    Sending POST request to http://localhost:4000/api/readings/add as JSON: {"temperature":"27.4","humidity":"85.1","pressure":"947","dust_concentration":"793","air_purity":"High Pollution"}
    Sending POST request to http://localhost:4000/api/readings/add as JSON: {"temperature":"28.0","humidity":"33.6","pressure":"936","dust_concentration":"622","air_purity":"High Pollution"}
    Sending POST request to http://localhost:4000/api/readings/add as JSON: {"temperature":"34.0","humidity":"14.8","pressure":"1077","dust_concentration":"813","air_purity":"High Pollution"}
    Sending POST request to http://localhost:4000/api/readings/add as JSON: {"temperature":"21.6","humidity":"24.7","pressure":"941","dust_concentration":"380","air_purity":"High Pollution"}
    Sending POST request to http://localhost:4000/api/readings/add as JSON: {"temperature":"16.7","humidity":"52.6","pressure":"1075","dust_concentration":"593","air_purity":"High Pollution"}
    Sending POST request to http://localhost:4000/api/readings/add as JSON: {"temperature":"31.6","humidity":"1.2","pressure":"999","dust_concentration":"530","air_purity":"High Pollution"}
    Sending POST request to http://localhost:4000/api/readings/add as JSON: {"temperature":"25.8","humidity":"56.8","pressure":"1054","dust_concentration":"990","air_purity":"High Pollution"}
    Sending POST request to http://localhost:4000/api/readings/add as JSON: {"temperature":"19.5","humidity":"78.9","pressure":"931","dust_concentration":"729","air_purity":"High Pollution"}
    Sending POST request to http://localhost:4000/api/readings/add as JSON: {"temperature":"27.5","humidity":"7.5","pressure":"1094","dust_concentration":"887","air_purity":"High Pollution"}
    Response from Ambi backend: "200"
    Response from Ambi backend: "200"
    Response from Ambi backend: "200"
    Response from Ambi backend: "200"
    Response from Ambi backend: "200"
    Response from Ambi backend: "200"
    Response from Ambi backend: "200"
    Response from Ambi backend: "200"
    Response from Ambi backend: "200"
    Response from Ambi backend: "200"
    Response from Ambi backend: "200"
    Response from Ambi backend: "200"
    Response from Ambi backend: "200"
    Response from Ambi backend: "200"
    Response from Ambi backend: "200"
    
    enhancement 
    opened by calebbourg 5
Owner
Rust Never Sleeps
Build real + useful open source software, master your craft of software development, all in an experienced community of developers from around the world.
Rust Never Sleeps
Crates.io library that provides high-level APIs for obtaining information on various entertainment media such as books, movies, comic books, anime, manga, and so on.

Crates.io library that provides high-level APIs for obtaining information on various entertainment media such as books, movies, comic books, anime, manga, and so on.

consumet-rs 5 Aug 13, 2023
Humidity & Temperature CLI datalogger for DHT22 sensor on Raspberry Pi.

Datalogger Humidity & Temperature CLI datalogger for DHT22 sensor on Raspberry Pi. Index Install Git Cargo Master branch Latest release from crates.io

Marco Radocchia 2 Aug 2, 2022
Code for working with edge-matching puzzles in the Eternity 2 family.

e2rs Code for working with edge-matching puzzles in the Eternity 2 family. This is a WIP sketch of some APIs and algs for representing and manipulatin

Matthew Pocock 3 Jan 18, 2023
Veryl: A Modern Hardware Description Language

Veryl Veryl is a modern hardware description language. This project is under the exploration phase of language design. If you have any idea, please op

null 26 Jan 3, 2023
High performance wlroots screen recording, featuring hardware encoding

wl-screenrec High performance wlroots based screen recorder. Uses dma-buf transfers to get surface, and uses the GPU to do both the pixel format conve

Russell Greene 32 Jan 21, 2023
A native screenshot tool for wlroots based compositors such as sway and river written in Rust

A native screenshot tool for wlroots based compositors such as sway and river written in Rust. X11 support coming soon.

Waycrate 66 Dec 28, 2022
👑 Show in-organization ranking of GitHub activities such as review count.

gh-ranking Show in-organization ranking of GitHub activities such as review count. Installation gh extension install yukukotani/gh-ranking Usage USAG

Yuku Kotani 3 Dec 28, 2022
A top-down arena shooter roguelite in which you're a mythical marshmallow god fighting against peasant munchies such as chocolates, jellies, or candies!

Mythmellow A top-down arena shooter roguelite in which you're a mythical marshmallow god fighting against peasant munchies such as chocolates, jellies

Umut 3 Oct 16, 2023
A top-down arena shooter roguelite in which you're a mythical marshmallow god fighting against peasant munchies such as chocolates, jellies, or candies!

Mythmallow A top-down arena shooter roguelite in which you're a mythical marshmallow god fighting against peasant munchies such as chocolates, jellies

Umut 3 Oct 29, 2023
Display ZFS datasets' I/O in real time

ztop Display ZFS datasets' I/O in real time Overview ztop is like top, but for ZFS datasets. It displays the real-time activity for datasets. The buil

Alan Somers 40 Nov 23, 2022
Real-time CLI level meter built in Rust.

Meter This is a very simple command line utility written in Rust for measuring the gain of a microphone. It displays the values in dBFS. This is usefu

Chris Burgess 16 Sep 8, 2022
An experimental real-time operating system (RTOS) written in Rust

An experimental real-time operating system (RTOS) written in Rust

null 0 Nov 14, 2022
Real-time stock tickers from the command-line. Written in Rust.

ticker-rs Real-time stock tickers from the command-line written in Rust. CLI tool using the Yahoo Finance API as a data source. It features colored ou

Patrick Stadler 4 Nov 17, 2022
Minimal and blazing-fast file server. For real, this time.

Zy Minimal and blazing-fast file server. For real, this time. Features Single Page Application support Partial responses (Range support) Cross-Origin

Miraculous Owonubi 17 Dec 18, 2022
🛡️ Terminal-based, real-time traffic monitoring and statistics for your AdGuard Home instance

AdGuardian-Term Terminal-based, real-time traffic monitoring and statistics for your AdGuard Home instance About AdGuardian Terminal Eddition - Keep a

Alicia Sykes 629 Jun 14, 2023
Revolutionize handheld gaming with adaptive game settings. Optimize graphics and gameplay experience based on real-time system metrics. Open-source project empowering developers to enhance games on portable devices

Welcome to the server-side application for the HarmonyLink project. This innovative software is developed with the Rust programming language and is ai

Jordon Brooks 5 Jun 28, 2023
Display near-real-time satellite imagery on your desktop.

Satpaper Display near-real-time satellite imagery on your desktop. (Click to see full-size version) Satpaper generates live wallpapers for your deskto

null 148 Oct 10, 2023
Kiomet.com real-time strategy game

Kiomet.com Kiomet.com is an online multiplayer real-time strategy game. Command your forces wisely and prepare for intense battles! Build Instructions

Softbear 26 Oct 10, 2023