npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

amnisio

v0.0.56

Published

Write functional reactive code for various platforms using TypeScript

Downloads

18

Readme

AmnisIO

Write reactive programs for various platforms using TypeScript.

Inspired by Cycle.js and powered by PlatformIO

The what, the why, and the how

AmnisIO will enable you to write IoT programs in a reactive way.

Every IoT program, from blinking LEDs to switching, is basically a program that reacts to inputs from the device, and pushes outputs to the device. Why not write it declaratively, instead of writing it imperatively? One of the main inhibitors to this approach is the need to write programs for IoT devices in C. A dynamic language like JavaScript allows you to use FRP in order to write the same programs reactively. Enabling people to write IoT programs in JavaScript, and having it transpiled into a C program that can run on the IoT device (as opposed to having a serial connection) is the goal of this project.

Towards this, we have built a small stream library in C called rivulet, and we expose it via TypeScript. It is a compact library with limited but useful functions which will enable us to get started with reactive programming quickly. Initially, we will be limited to the use of only this library, but we hope to expand our horizons in future.

We hope to enable you to write, in TypeScript, a blinking LEDs program:

import { periodic } from '@amnisio/rivulet';
import { Sources, Sinks, HIGH, LOW, run } from '@amnisio/arduino-uno';

// Read the LED pin value every 500 ms and toggle it
const blink = (arduino: Sources): Sinks => ({
  LED$:
    periodic(500)
      .sample(arduino.LED$)
      .map(x => x == LOW ? HIGH : LOW)
});

run(blink);

and be able to run the program in your Arduino/Genuino UNO, for example. We use a transpiler called typewriter and convert this into C code that is compatible with the embedded platform that you choose to work on, and the platform runs the code natively.

The Arduino UNO used here is an example, we will be building towards every platform that is targetable. We will be using the wonderful PlatformIO in order to accomplish this.

Status

| Area | Status | Repository | | :--- | :--- | :--- | | Stream Library (C) | Ready | rivulet | | Stream Library (TS) | Ready | rivulet | | Board/Framework (C) | Ready for Arduino UNO | gyrus | | Board/Framework (TS) | Ready for Arduino UNO | gyrus | | Transpiler (TS/C) | Ready | typewriter | | AmnisIO CLI (TS) | Ready | AmnisIO |

Getting Started

We are working on getting a CLI for bootstrapping. For now, we can work with the Arduino Uno.

Please install platformio. Instructions here. The platformio executable should be added to the PATH.

mkdir amnisio_test
cd amnisio_test
npm init
npm install amnisio --save-dev

Add a configuration file

touch .amnisio.config.json

with the following contents

{
    "source": "app.ts",
    "output": "app.c",
    "board": "uno"
}

Add the following scripts to your package.json:

{
  "initialize": "amnisio init",
  "build": "amnisio build",
  "deploy": "amnisio deploy"
}

Now, time to initialize the project.

npm run initialize

The arduino uno board configuration (which is the one available at the moment, and entered in the config file) is initialized. The necessary files are downloaded, so please be patient while the initialization happens. Once the initialization is complete, connect your arduino to the computer and get ready (Windows users make sure the required USB drivers are installed).

Add a source file (this is the source that we mentioned in the config, so it should be at the app root)

touch app.ts

with the following contents

import { periodic } from '@amnisio/rivulet';
import { Sources, HIGH, LOW, run, createSinks } from '@amnisio/arduino-uno';

const blink = (arduino: Sources) => {
  const sinks = createSinks();
  sinks.LED$ =
    periodic(500)
      .sample(arduino.LED$)
      .map(led => led == LOW ? HIGH : LOW);
  return sinks;
};

run(blink);

That's your first app! It blinks the LED every 500 milliseconds. Let's deploy the app and see it in full glory:

npm run deploy

The TypeScript code is transpiled, and PlatformIO deploys our code to the platform. In a few moments, you should see your UNO blinking its LED. Congrats, you have your first AmnisIO application running on your Arduino UNO!

If you would like to play around, try changing the code to sample arduino.D2$ instead of arduino.LED$. This will make the LED respond to the value of the D2 pin of the UNO. The LED stays ON whenever the D2 pin is LOW, but once you provide a value to the D2 pin, the LED goes OFF. Kindly note that we sample the D2 pin values so we will only recognize the change once every 500ms.

Go on, try it! Play around with the sampling values to see what happens.

You can find more samples for the Arduino UNO here. We're adding more samples as you're reading this.

How it works

We provide the stream library, the application library, and the platform specific implementation in C. Accompanying them are the TypeScript interface and counterparts. The AmnisIO configurator provides the correct implementations based on the required platform. This area is customizable so new platforms can be added easily. The configurator also provides the necessary context to the transpiler to intelligently transpile what is required into C. We then rely on configuring platformio to pick the correct platform libraries and to build and deploy our code to the device. Here's a diagrammatic representation if it helps:

amnisio-architecture

Contributing

With such a lofty goal, we will need all the help we can get. However, at the moment, we are in a very nascent stage and it would take us some time to set up some guidelines towards contribution, etc. Please feel free to open up issues on this repo till then.