{"id":13414333,"url":"https://github.com/mongoose-os-apps/losant-temp-sensor","last_synced_at":"2025-04-23T21:44:37.514Z","repository":{"id":103985073,"uuid":"121751745","full_name":"mongoose-os-apps/losant-temp-sensor","owner":"mongoose-os-apps","description":":thermometer: A Mongoose OS app for sending temperature readings of ESP32 to Losant.","archived":false,"fork":false,"pushed_at":"2020-08-20T19:03:17.000Z","size":210,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-23T21:44:32.996Z","etag":null,"topics":["esp32","esp822","espressif","losant","mongoose-os","mongoose-os-app","mqtt","temperature-sensor"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mongoose-os-apps.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"patreon":"UtkarshVerma","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":"UtkarshVerma","issuehunt":null,"otechie":null,"custom":null}},"created_at":"2018-02-16T13:05:47.000Z","updated_at":"2023-07-14T12:47:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"f66578ac-f5f8-46ac-b083-eb0cf7cfc024","html_url":"https://github.com/mongoose-os-apps/losant-temp-sensor","commit_stats":null,"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongoose-os-apps%2Flosant-temp-sensor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongoose-os-apps%2Flosant-temp-sensor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongoose-os-apps%2Flosant-temp-sensor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongoose-os-apps%2Flosant-temp-sensor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mongoose-os-apps","download_url":"https://codeload.github.com/mongoose-os-apps/losant-temp-sensor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250522292,"owners_count":21444509,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["esp32","esp822","espressif","losant","mongoose-os","mongoose-os-app","mqtt","temperature-sensor"],"created_at":"2024-07-30T21:00:19.316Z","updated_at":"2025-04-23T21:44:37.496Z","avatar_url":"https://github.com/mongoose-os-apps.png","language":"JavaScript","funding_links":["https://patreon.com/UtkarshVerma","https://liberapay.com/UtkarshVerma"],"categories":["Awesome Mongoose OS [![Awesome](https://awesome.re/badge.svg)](https://awesome.re)"],"sub_categories":["Official Examples"],"readme":"# losant-temp-sensor\n\n#### A [Mongoose OS](https://mongoose-os.com) app for sending temperature readings to [Losant](https://www.losant.com). \n\n\u003cp align=\"center\"\u003e\u003cimg src=\"/graph.png\" alt=\"Demo graph\"/\u003e\u003c/p\u003e\n\nThis app lets you configure your device so that it can **publish its temperature readings to Losant via MQTT periodically** and **power efficiently** by utilizing the deep sleep feature of ESP32.  \nThis app is good for you if you're a beginner with IoT since it *allows quick testing of [Mongoose OS](https://mongoose-os.com) and MQTT brokers*(here, [Losant](https://www.losant.com)). I emphasize on the **quick testing** part because *to get this app to work, **all you need is a USB cable and an ESP32 development board.***\nThe above picture shows the graph of my ESP32 temperature readings recorded via this app and plotted on the server-side using [Losant's dashboards](https://docs.losant.com/dashboards/overview).\n\n### Theory\nThis app relies on the **internal temperature sensor** of IoT devices, which gives the temperature of the MCU.\nThroughout this app, **it has been assumned that the MCU temperature must be greater than the actual temperature by a fixed quantity**, an \"offset\" if you like. Therefore, *the app first finds this \"offset\" by initially comparing the MCU temperature with a [reference temperature](#temperaturebasis)(the actual ambient temperature) specified by the user at the time of flashing the firmware*. Once the offset has been calculated by the app, it will publish the approximated temperature(`mcu_temperature - offset`).\nSince the device simply repeats the cycle in roughly the same time every time and  then sleeps, therefore variations get minimised and the approximated temperature resembles the ambient temperatue.\n\n### Supported Hardware\n- ESP32\n\n---\n\n## Installation\n\nFor installing this app, it is necessary that you already have the `mos` tool installed on your machine. If not, then do so by following the instructions given here: [mos Installation Guide](https://mongoose-os.com/software.html).  \nOnce installed, launch the mos tool or CLI, whatever you prefer, and proceed with the steps.\n\n### 1. Clone the `losant-temp-sensor` app\n```bash\nmos clone https://github.com/mongoose-os-apps/losant-temp-sensor\n```\n\n### 2. Build the firmware and flash it\nOpen the cloned repository directory in your CLI and run the following command.\n```bash\nmos build --platform esp32 \u0026\u0026 mos flash\n```\n\n### 3. Configure WiFi\nAfter successful flashing, **wait for five seconds** to allow the device to boot and then configure wifi for the device using the given command.\n```bash\nmos wifi \"\u003cyour WiFi SSID\u003e\" \"\u003cyour WiFi password\u003e\"\n```\nFor example:\n```\nmos wifi \"Home WiFi\" \"home@123\"\n```\n\n### 4. Configure the app\nThis app requires a little configuration before using to suit the user. The configurations can be made to the app using the `mos config-set` command.\n```bash\nmos config-set temperature.basis=\u003cbasis temperature\u003e \\\n    temperature.unit=\"\u003ctemperature unit\u003e\"\n```\nYou can also customize the app to more extent through the variables documented below in [App Configuration](#app-configuration) section.\n\n### 5. Set up Losant\nTo use this app, you are required to have a **device** as well as an **application** set up on Losant. To do so, you may refer to these Losant documentations:\n- [Creating A Device](https://docs.losant.com/devices/overview/)\n- [Generating Access Keys](https://docs.losant.com/applications/access-keys/)\n\nWhile creating the device, be sure to add a device attribute with the following properties:\n1. **Name**: temperature, **Data Type**: Number\n2. **Name**: offset, **Data Type**: Number\n3. **Name**: unit, **Data Type**: String\n\n### 6. Configure the MQTT connection to Losant\nSet up the MQTT credentials on your Mongoose OS flashed device using the following command.\n```\nmos config-set device.id=\u003cyour Losant device id\u003e \\\n  mqtt.client_id=\u003cyour Losant device id\u003e \\\n  mqtt.user=\u003cyour Losant access key \u003e \\\n  mqtt.pass=\u003cyour Losant access secret\u003e\n```  \nThe **Device ID** can be obtained on Losant under the **Devices** section of your app.\nThe **Access Key** and **Access Secret** can be obtained on Losant. If you don't already have one at your disposal, you may generate one by following the official instructions stated in the [Losant Docs](https://docs.losant.com/applications/access-keys/).\n\nOnce these are set up, your device should now be sending data to Losant.\n\n### 7. Additional Losant Set-up\nOnce you've done all the above steps, you may use the temperature readings for doing anything by accessing the attributes of your device(e.g. temperature). I used the `temperature` attribute to plot a graph using [Losant's dashboards](https://docs.losant.com/dashboards/overview).\n\n---\n\n## App Configuration\nSome configurations have to be set for the app to work optimally. They are as stated below:\n\n### Edit mode\n\nSince `losant-temp-sensor` app goes into **deep sleep** soon after publishing data to MQTT broker, therefore passing commands via the console isn't possible as the device shuts off its UART connection. This is where **edit mode** steps in. It is a mode that this app has in which **deep sleep is disabled for one boot cycle**.\nThis mode can be activated/deactivated by pressing the `Flash` or `Boot` button after the device has finished booting. The built-in LED indicates whether this mode is on or off.\n**This mode must be turned on if you wish to configure the app after setting up WiFi and MQTT.**\n\n\u003e The best way to check if the device has booted or not is by seeing the device logs using the `mos console` command.\n\n### `temperature.basis`\nThe app needs the actual ambient temperature to be specified to it initially through the `temperature.basis` key. This helps the app in approximating the ambient temperature using the internal temperature readings alone.\nThe basis temperature can be specified using the following command:\n```bash\n# Example for setting basis temperature to 30 units\nmos config-set temperature.basis=30\n```\nIf not specified by the user, `temperature.basis` **defaults to 24 units**. \n\n### `temperature.unit`\nThis app has the facility to send temperature to Losant in either **Celsius** or **Fahrenheit**.\nTo specify the temperature unit of your choice, use this command:\n```bash\n# Example for setting temperature unit to Celsius\nmos config-set temperature.unit=\"celsius\"   #or \"fahrenheit\"\n```\nIf not specified by the user, `temperature.unit` **defaults to Celsius**.\n\n### `sleep_duration` \nIt is up to you to set the interval, *during which the device will undergo deep sleep*, between two consistent temperature readings. `sleep_duration` key contains the value which decides the **sleep time** of the device, that is the amount of time(in minutes) after which it has to wake and send another temperature reading to Losant.\nThe sleep duration can be specified using the command:\n```bash\n# Example for setting sleep_duration to 20 minutes\nmos config-set sleep_duration=20\n```\nIf not specified by the user, `sleep_duration` **defaults to 10 minutes**.\n\n### `led.gpio`\nThis key points to the GPIO you wish to set up as an LED output.\nTo specify the LED GPIO, use this command:\n```bash\n# Example to set GPIO2 as LED pin\nmos config-set led.gpio=2\n```\nIf not specified, `led.gpio` **defaults to GPIO2**.\n\u003e Self note: Prefer default value recommended by Mongoose OS after [this PR](https://github.com/mongoose-os-libs/boards/pull/1) is merged.\n\n### `led.isOnWhenHigh`\nThis key tells the app when the LED lights up on HIGH input or not.\nTo specify this key, use this command:\n```bash\n# Example for telling the app that LED lights up on HIGH input\nmos config-set led.isOnWhenHigh=true\n```\nIf not specified by the user, this key **defaults to a value recommended by Mongoose OS for your board**. Therefore it is better to leave this key unspecified.\n\n### `button.gpio`\nThis key points to the GPIO you wish to set up as a button for the app. This button will be responsible for entering **edit mode**.\nTo specify the button GPIO, use this command:\n```bash\n# Example to set GPIO0 as LED pin\nmos config-set button.gpio=0\n```\nIf not specified, this key **defaults to a value recommended by Mongoose OS for your device**. Therefore it is better to leave this key unspecified.\n\n### `button.hasPullUp`\nThis key tells the app whether the button GPIO has a pull up resistor or not.\nTo specify this key, use this command:\n```bash\n# Example for telling the app that button GPIO has a pull down resistor\nmos config-set button.hasPullUp=false\n```\nIf not specified by the user, this key **defaults to a value recommended by Mongoose OS for your board**. Therefore it is better to leave this key unspecified if you haven't modified the `button.gpio` key.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmongoose-os-apps%2Flosant-temp-sensor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmongoose-os-apps%2Flosant-temp-sensor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmongoose-os-apps%2Flosant-temp-sensor/lists"}