Compare commits

..

No commits in common. "113384b6ce84e63028076f917e1dde4870fa5497" and "af4f5a850c1a521fcef160e65ac829cf33a12d1a" have entirely different histories.

4 changed files with 5 additions and 70 deletions

View file

@ -1,10 +1,9 @@
import gleam/erlang/process
import gleam/list
import gleam/otp/actor
import sensors
pub type Subscriber =
process.Subject(sensors.SensorReading)
process.Subject(String)
pub type Message {
Subscribe(subscriber: Subscriber)
@ -25,10 +24,7 @@ fn handle_message(
}
Proc -> {
list.each(subscribers, fn(subscriber) {
process.send(
subscriber,
sensors.SensorReading(sensors.Temperature, 26.6),
)
process.send(subscriber, "Hello from dummy mqtt action")
})
actor.continue(subscribers)
}

View file

@ -1,42 +0,0 @@
import gleam/float
import gleam/io
pub type Sensor {
Temperature
Humidity
Pressure
ParticalMatterOne
ParticalMatterTwoPointFive
ParticalMatterTen
}
pub type SensorReading {
SensorReading(sensor: Sensor, value: Float)
}
pub fn sensor_name(sensor: Sensor) -> String {
case sensor {
Temperature -> "Temperature"
Humidity -> "Humidity"
Pressure -> "Pressure"
ParticalMatterOne -> "Partical matter 1 micron or less"
ParticalMatterTwoPointFive -> "Partical matter 2.5 micros or less"
ParticalMatterTen -> "Partical matter 10 microns or less"
}
}
pub fn print_sensor_reading(reading: SensorReading) -> Nil {
let sensor_name = sensor_name(reading.sensor)
io.println(sensor_name <> ": " <> float.to_string(reading.value))
}
pub fn sensor_unit(sensor: Sensor) -> String {
case sensor {
Temperature -> "°C"
Humidity -> "%"
Pressure -> "hPa"
ParticalMatterOne -> "µg/m³"
ParticalMatterTwoPointFive -> "µg/m³"
ParticalMatterTen -> "µg/m³"
}
}

View file

@ -2,7 +2,6 @@ import config
import gleam/erlang/process
import gleam/io
import mqtt_dummy
import sensors
pub fn main() -> Nil {
case config.load_config() {
@ -38,12 +37,13 @@ pub fn main() -> Nil {
}
fn receive_and_reschedule(
mailbox: process.Subject(sensors.SensorReading),
mailbox: process.Subject(String),
subject: process.Subject(mqtt_dummy.Message),
) -> Nil {
case process.receive(mailbox, 2000) {
Ok(msg) -> {
sensors.print_sensor_reading(msg)
io.println("Got message: " <> msg)
// Reschedule the next Proc message
process.send_after(subject, 1000, mqtt_dummy.Proc)
receive_and_reschedule(mailbox, subject)
}

View file

@ -1,19 +0,0 @@
import gleeunit
import gleeunit/should
import sensors
pub fn main() -> Nil {
gleeunit.main()
}
// gleeunit test functions end in `_test`
pub fn file_read_test() {
let reading =
sensors.sensor_name(sensors.Temperature)
<> " "
<> "20.5"
<> " "
<> sensors.sensor_unit(sensors.Temperature)
reading
|> should.equal("Temperature 20.5 °C")
}