Coder Social home page Coder Social logo

creatures's Introduction

creatures

This is a "Things" simulator (think IOT)

See it in action

Proudly hosted on https://www.clever-cloud.com/

Create a new sensor

Here TemperatureSensor has only one component: TemperatureComponent

class TemperatureSensor extends Thing {
  constructor({id, minTemperature, maxTemperature, delay}) {
    super({id, delay});
    this.temperature = new TemperatureComponent({minTemperature, maxTemperature})
  }

But you can imagine a DHT sensor like that:

class TemperatureSensor extends Thing {
  constructor({id, minTemperature, maxTemperature, minHumidity, maxHumidity, delay}) {
    super({id, delay});
    this.temperature = new TemperatureComponent({minTemperature, maxTemperature})
    this.humidity = new HumidityComponent({minHumidity, maxHumidity})
  }
  • a thing must have:
    • a constructor
    • a generateData() method
      • This method is called at a frequency defined by delay
      • you start the data generation/simulation like that: thing.start("generateData") (so, you can name generateData otherwise)
    • a getData() method

Instantiate "a lot of" sensors

See main.js

Eg: "I want 100 humidity sensors"

// Generate n humidity sensors
let humiditySensors = [...Array(100).keys()].map(item => {
  let h = new HumiditySensor({id:`h${item}`, delay:randomDelay()});
  h.start("generateData");
  return  h;
});

Create an "API" to get the sensors data

See main.js

Eg: "I want to get all temperature sensors"

app.get('/sensors/temperature', authorized, (req, res) => {
  res.send(temperatureSensors.map(sensor => sensor.getData()));
});

Add a new sensor

ToDo

  • security (key in the header)
  • "swaggify" the API
  • add other REST Methods to the Things (eg: POST)
  • add other protocols (eg: CoAP, MQTT, ...)
  • add "boids" (moving sensors)
  • refactoring
  • ...

creatures's People

Contributors

k33g avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.