An open API service indexing awesome lists of open source software.

https://github.com/eval/otarta

An MQTT-library for ClojureScript
https://github.com/eval/otarta

clojure clojurescript mqtt

Last synced: 6 days ago
JSON representation

An MQTT-library for ClojureScript

Awesome Lists containing this project

README

        

# Otarta

*Canonical repository: https://gitlab.com/eval/otarta*

[![cljdoc badge](https://img.shields.io/badge/cljdoc-latest-blue.svg)](https://cljdoc.org/d/eval/otarta/CURRENT)
[![cljdoc badge](https://img.shields.io/badge/cljdoc-0.3.1-blue.svg)](https://cljdoc.org/d/eval/otarta/0.3.1)
[![discuss at Clojurians-Zulip](https://img.shields.io/badge/clojurians%20zulip-otarta-brightgreen.svg)](https://clojurians.zulipchat.com/#narrow/stream/151157-Otarta)
[![pipeline status](https://gitlab.com/eval/otarta/badges/master/pipeline.svg)](https://gitlab.com/eval/otarta/commits/master)
[![Clojars Project](https://img.shields.io/clojars/v/eval/otarta.svg)](https://clojars.org/eval/otarta)

An MQTT-library for ClojureScript.

_NOTE: this is pre-alpha software with an API that will change (see the [CHANGELOG](./CHANGELOG.md) for breaking changes)_

## Installation

Leiningen:
```clojure
[eval/otarta "0.3.1"]
```

Deps:
```clojure
eval/otarta {:mvn/version "0.3.1"}
```

## Examples

* [CI-Dashboard](https://eval.gitlab.io/ci-dashboard/) (source: https://gitlab.com/eval/ci-dashboard)

## Usage

The following code assumes:
- being in a browser (ie `js/WebSockets` exists. For Node.js [see below](README.md#nodejs).)
- a websocket-enabled MQTT-broker on `localhost:9001` (eg via `docker run --rm -ti -p 9001:9001 toke/mosquitto`)

```clojure
(ns example.core
(:require-macros [cljs.core.async.macros :refer [go go-loop]])
(:require [cljs.core.async :as a :refer [> buff (mqtt-fmt/-read mqtt-fmt/string) extract-temperature))
(-write [_fmt v]
(->> v (mqtt-fmt/-write mqtt-fmt/string)))))
```

### Node.js

You should provide a W3C compatible websocket when running via Node.js.
I've had good experience with [this websocket-library (>= v1.0.28)](https://www.npmjs.com/package/websocket).

With the library included in your project (see https://clojurescript.org/guides/webpack for details), the following will initialize `js/WebSocket`:

```clojure
(ns example.core
(:require [websocket]))

(set! js/WebSocket (.-w3cwebsocket websocket))
```

## Limitations

- only QoS 0
- only clean-session
- no reconnect built-in
- untested for large payloads (ie more than a couple of KB)

## Development

### Testing

Via [cljs-test-runner](https://github.com/Olical/cljs-test-runner/):

Via [cljs-test-runner](https://github.com/Olical/cljs-test-runner/):

```bash
# once
$ clojure -Atest

# watching
$ clojure -Atest-watch

# specific tests
(deftest ^{:focus true} only-this-test ...)
$ clojure -Atest-watch -i :focus

# more options:
$ clojure -Atest-watch --help
```

### Figwheel

```bash
# start figwheel
$ make figwheel

# wait till compiled and then from other shell:
$ node target/app.js

# then from emacs:
# M-x cider-connect with host: localhost and port: 7890
# from repl:
user> (figwheel/cljs-repl)
;; prompt changes to:
cljs.user>
;; to quickly see what otarta can do:
;; - evaluate the otarta.main namespace
;; - then eval the comment-section of otarta.main line by line
```

See [CIDER docs](https://cider.readthedocs.io/en/latest/interactive_programming/) what you can do.

## Release

### Install locally

- (ensure no CLJ_CONFIG and MAVEN_OPTS env variables are set - this to target ~/.m2)
- ensure dependencies in pom.xml up to date
- clj -Spom
- ensure pom.xml with new version
- cp pom.xml{.template,}
- gsed -i 's/$RELEASE_VERSION/1.2.3/' pom.xml
- make mvn-install
- testdrive locally

### Deploy to Clojars

- create (pre-)tag
- push to CI

## License

Copyright (c) 2018 Gert Goet, ThinkCreate
Copyright (c) 2018 Alliander N.V.
See [LICENSE](./LICENSE).

For licenses of third-party software that this software uses, see [LICENSE-3RD-PARTY](./LICENSE-3RD-PARTY).