项目作者: riot-framework

项目描述 :
Giter8 template for an Akka Streams projectusing RIoT, RIoT-Control, and SBT
高级语言: Scala
项目地址: git://github.com/riot-framework/streams.g8.git
创建时间: 2019-09-18T16:13:58Z
项目社区:https://github.com/riot-framework/streams.g8

开源协议:Creative Commons Zero v1.0 Universal

下载


RIoT Streams Template

This Giter8 template will set up a sample RIoT SBT project.
You will need the Scala Build Tool (sbt) to deploy this example code to your Raspberry Pi or similar device.

The Application class in the default package is a Java main class that briefly sets up Akka Streams for you.
You can then instantiate further RIoT Akka Streams components by using the RIoT builders, e.g.:

  1. // General Purpose I/O pins: Input Source, Output flow step, Output Sink
  2. Source<State, NotUsed> gpio15 =
  3. GPIO.in(15).withPullupResistor().asSource(system, mat);
  4. Flow<State, State, NotUsed> gpio7 =
  5. GPIO.out(7).initiallyHigh().asFlow(system);
  6. Sink<GPIO.State, NotUsed> gpio9 =
  7. GPIO.out(9).initiallyLow().shuttingDownLow().asSink(system);
  8. // I2C: Raw device sink, Flow step with custom driver logic
  9. final Sink<RawI2CProtocol.Command, NotUsed> rawSink =
  10. I2C.rawDevice().onBus(1).at(0x12).asSink(system);
  11. Flow<MyDriver.InputMessage, MyDriver.OutputMessage, NotUsed> myDevice =
  12. I2C.device(myDriverConfig).onBus(1).at(MyDriver.ADDRESS).asFlow(system);
  13. // where 'MyDriver' is a class encapsulating the device's specific I2C protocol
  14. // SPI and more coming in future releases...

These can be mixed with Akka treams components from other sources, such as the Alpakka Project, which contains a number of community-contributed integration components, for example an MQTT sink and source.

The components can then be assembled into streams and run:

  1. tickSource.via(gpio7).to(logSink).run(mat);

RIoT comes with a tool (RIoT Control) which simplifies deployment to your Raspberry Pi. This tool is already preconfigured in this project. Set-up the name of your device and the user credentials to use for deployment in the build.sbt file:

  1. riotTargets := Seq(
  2. riotTarget("raspberrypi", "pi", "raspberry")
  3. )

Then run sbt riotRun to compile your code, copy it to the device, and run it locally.

Once you’re happy with the result, just run sbt riotInstall to set up your code as a service, which will automatically start when the device boots.

Template license

Written in 2019 by Frederic Auberson

To the extent possible under law, the author(s) have dedicated all copyright and related
and neighboring rights to this template to the public domain worldwide.
This template is distributed without any warranty. See http://creativecommons.org/publicdomain/zero/1.0.