avbentem / airtime-calculator

Airtime calculator for LoRaWAN
https://avbentem.github.io/airtime-calculator
MIT License
49 stars 6 forks source link
lora lorawan react typescript

Airtime calculator for LoRaWAN

A basic React UI for the formulas defined in Semtech's LoRa Modem Designer's Guide (AN1200.13), showing the airtime for data rates as used in the frequency plans of The Things Network (TTN), and showing the limitations that apply to the TTN public network.

See it in action on https://avbentem.github.io/airtime-calculator.

Wishlist

Next versions may include:

Data rates and frequency plans

The frequency plans from which the data rates are shown, are those of The Things Network. They are based on the frequency plans and the LoRaWAN Regional Parameters v1.0.2rB, and defined in config.json.

Some frequency plans have very different data rates for uplinks and downlinks; for those distinct "regions" are defined in this application, like for US902 (uplink) and US902 DL (downlink). Others share (most) of the data rates, like EU868.

Maximum duty cycle and maximum dwell time limitations

Maximum payload size

The LoRaWAN specification(s) defines multiple options for the maximum payload size, like depending on dwell time settings, and with or without support for a possible repeater encapsulation.

In the early specifications, these choices are quite confusing as often smaller maximum values are listed when no maximum dwell times apply. However, the February 2020 LoRaWAN Regional Parameters RP002-1.0.1 states that no MACPayload may be larger than 230 bytes, regardless of dwell time limitations, and in that version the numbers have been adjusted as well.

This calculator uses the maximum payload sizes from RP002-1.0.1, which allow for a possible repeater encapsulation and do not take maximum dwell times into account. If the device will never operate under a repeater then the maximum size could be a bit larger. If dwell times have been defined then those will generate warnings in the calculator regardless the maximum payload size, allowing users to whom those dwell times do not apply to still see the correct (higher) maximum payload sizes.

Time on air

Copying results

The browser's copy event is mapped as follows:

For the line breaks in the results grid, this uses a format that is very specific to the automatic conversion from HTML to Markdown in Discourse, like as used on the TTN Forum: Discourse replaces <br> with \n but then rejects \n in table cells. As a workaround, <br> is outputted as &lt;br>, which is handled as expected in Discourse's editor but needs some editing when pasted elsewhere. Of course, using the static results is not quite useful anyhow.

For text/plain no URL is added, as Discourse prefers the plain text content if that is longer than the HTML.

URL structure

This application was created with sharable URLs in mind, so almost every user input yields an updated URL:

URL structure and GitHub Pages

To serve this single-page application from GitHub Pages, some trickery with a JavaScript redirect in a custom 404 page is needed. Unfortunately, some browsers (such as Brave) may try to be helpful and show an option like "Do you want to check if a saved version is available on the Wayback Machine?" even when properly executing the expected redirect. It's unclear why the final 200 OK removes the banner for some sites in Brave, but not for GitHub Pages.

Development and deployment

This project was bootstrapped with Create React App.

To use a limited bundle for Plotly (removing about 690 kB from the build), while using the typings of the full bundle, a paths alias configuration is used in tsconfig.json. However, during testing or building, Create React App would boldly remove that:

> react-scripts build

The following changes are being made to your tsconfig.json file:
  - compilerOptions.paths must not be set (aliased imports are not supported)

...

TypeScript error in /src/components/result/Graph.tsx(1,20):
Could not find a declaration file for module 'plotly.js-basic-dist'

To mitigate that, some trickery with extends is used instead. This will still show the same message for npm test and npm run build, and will even pretty-format the base tsconfig.json, but in the end it won't touch the extends and use tsconfig-paths.json.

NPM commands

In the project directory, run:

Linting and Prettier

A pre-commit hook ensures that linting errors and formatting errors cannot be committed. To allow Prettier rules to supersede any formatting rules that might be defined by a linter, it is configured to run as a plugin for both ESLint and stylelint, and to explicitly run for the few file types not handled by either of those.

Note that the pre-commit hook uses lint-staged, which temporarily hides unstaged changes to partially staged files. This may make your IDE show warnings about files that were changed outside of the IDE.

Beware that Sourcetree might silently skip the pre-commit hook.

Editor setup

WebStorm