# @mangar2/opensensemap

> sends data to opensensemap.org

Latest version **2.0.1** (published 2020-12-11) · LGPL-3.0-or-later license · 0 weekly downloads

## Install

```sh
npm install @mangar2/opensensemap
pnpm add @mangar2/opensensemap
yarn add @mangar2/opensensemap
bun add @mangar2/opensensemap
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2020-12-11 |
| First published | 2020-01-14 |
| Weekly downloads | 0 |
| License | LGPL-3.0-or-later |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 13.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Volker Böhm |
| Maintainers | mangar2 |
| Keywords | opensensemap |

## Links

- npm: https://www.npmjs.com/package/@mangar2/opensensemap
- Repository: https://github.com/Mangar2/yaha/tree/master/node_modules/@mangar2/opensensemap
- Homepage: https://github.com/Mangar2/yaha.git
- npm.io page: https://npm.io/package/@mangar2/opensensemap

## Dependencies (2)

- [@mangar2/message](https://npm.io/package/@mangar2/message.md) latest
- [@mangar2/httpservice](https://npm.io/package/@mangar2/httpservice.md) latest

## Recent versions

- 2.0.1 (latest) — 2020-12-11
- 1.0.3 — 2020-12-11
- 1.0.1 — 2020-02-29
- 1.0.0 — 2020-01-14

## README

<!-- This file is generated by jsmddoc version 0.1 -->

# Abstract

Interface to the opensense map service . Use it to send data to opensense map .

## Contents

- [Meta](#Meta)
- [Type definitions](#Type-definitions)
- [Global Functions](#Global-functions)
  - [prepare](#prepare)
- [Class OpensenseMap](#Class-OpensenseMap)
  - [Parameters](#OpensenseMap-Parameters)
  - [Methods](#OpensenseMap-Methods)
    - [getSubscriptions](#getSubscriptions)
    - [handleMessage](#handleMessage)

## Meta

| | |
| --- | --- |
| **File** | index.js |
| **Abstract** | Interface to the opensense map service . Use it to send data to opensense map . |
| **Author** | Volker Böhm |
| **Copyright** | Copyright ( c ) 2020 Volker Böhm |
| **License** | This software is licensed under the GNU LESSER GENERAL PUBLIC LICENSE Version 3 . It is furnished "as is" , without any support , and with no warranty , express or implied , as to its usefulness for any purpose . |

## Type definitions

### Sensor {Object}

| Name | Type | Description |
| ---- | ---- | ------- |
| `name` | `string` | name of the sensor | |
| `unit` | `string` | unit of the sensor | |
| `topic` | `string` | topic the sensor is matched to | |
| `id` | `string` | opensensmap unique id | |

### Sensors {Array.<Sensor>}


## Global functions

### prepare

`prepare (config, opensenseMap) => {OpensenseMap}`

Prepares the object

#### prepare Parameters

| Name | Type | Attribute | Default | Description |
| ---------- | ------------ | ------------ | ------------ | ----------------- |
| `config` | `Object` |  |  | automation configuration | |
| `opensenseMap` | `OpensenseMap` | optional | null | existing automation class | |

#### prepare returns

| Type | Description |
| ---- | ----------- |
| `OpensenseMap` | the prepared automation object |

## Class OpensenseMap

`new OpensenseMap(config)`

Creates a class with the ability to publish information to the opensensemap service

### Example

```javascript
const config =
{
  "station" : "your station name (optional)",
  "id" : "your station id",
  "host": "ingress.opensensemap.org",
  "port": 443,
  "sensors": [{
          "name": "temperature",
          "uint": "°C",
          "topic" : "topic/used/for/the/sensor",
          "id": "your sensor id"
   }]
}
const opensenseMap = new Opensensemap(config)

let result = await opensensemap.publish(
   new Message('topic/used/for/the/sensor', 2.61, 'test value' }
)
```

### OpensenseMap Parameters

| Name | Type | Description |
| ---------- | ------------ | ----------------- |
| `config` | `Object` | configuration ( sensors , . . . ) | |

#### config properties

| Name | Type | Attribute | Default | Description |
| ---------- | ------------ | ------------ | ------------ | ----------------- |
| `station` | `string` | optional |  | name of the station | |
| `id` | `string` |  |  | sensebox id ( provided by open sens map ) | |
| `host` | `string` |  |  | host of open sense map | |
| `port` | `port` | optional | 443 | portnumer of open sense map ( usually 443 ) | |
| `sensors` | `Sensors` |  |  | opensensemap sensor configuration | |

### OpensenseMap Methods

#### getSubscriptions

`getSubscriptions () => {Array.<string>}`

Gets the subscriptions for the service

##### getSubscriptions returns

| Type | Description |
| ---- | ----------- |
| `Array.<string>` | array of subscriptions |

#### handleMessage

`async handleMessage (message)`

Publishes a value to opensensemap ( you need an account to do this ) Publish data provided as Message to opensensemap . You need an account on opensensemap . org The message topic is mapped to the sensor id provided in the config object . The message value it the value to publish

##### handleMessage Parameters

| Name | Type | Description |
| ---------- | ------------ | ----------------- |
| `message` | `Message` | the data to publish on the opensensemap | |

#### message properties

| Name | Type | Description |
| ---------- | ------------ | ----------------- |
| `topic` | `string` | the topic is used to select the sensor id from config | |
| `value` | `number` | the value to publish to the sensor | |

---
_Source: https://npm.io/package/@mangar2/opensensemap · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
