Skip to content

bots-squad/creatures

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
  • ...