Compare commits

...

2 Commits

Author SHA1 Message Date
Dirk Heilig d4fce11f5a atomic update 2024-04-19 14:52:11 +02:00
Dirk Heilig 5f188442a1 reformate 2024-04-19 14:50:54 +02:00
3 changed files with 12 additions and 13 deletions

View File

@ -2,17 +2,16 @@ FROM debian:10
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y \
php7.3-cli php-json \
php-pear php-dev \
libmosquitto-dev libmosquitto1 mosquitto-clients \
php-yaml \
locales-all
php7.3-cli php-json \
php-pear php-dev \
libmosquitto-dev libmosquitto1 mosquitto-clients \
php-yaml \
locales-all
RUN pecl install Mosquitto-alpha
RUN echo "extension=mosquitto.so" >/etc/php/7.3/mods-available/mosquitto.ini
RUN echo "extension=mosquitto.so" > /etc/php/7.3/mods-available/mosquitto.ini
RUN ln -s /etc/php/7.3/mods-available/mosquitto.ini /etc/php/7.3/cli/conf.d/20-mosquitto.ini
ADD . /app
VOLUME /app/public
ENTRYPOINT /app/generator.php

View File

@ -1,7 +1,7 @@
mqtt:
host: $MQTT_HOST
user: $MQTT_USER
password: $MQTT_PASSWORD
host: $MQTT_HOST
user: $MQTT_USER
password: $MQTT_PASSWORD
variables:
doorstatus:
@ -16,4 +16,3 @@ variables:
werkstatt_temp:
topic: c3re/werkstatttemp
cast: float

View File

@ -35,7 +35,6 @@ $c->onMessage(function (\Mosquitto\Message $message) use (&$data, $conf) {
" unknown\n";
die(1);
}
var_dump($data);
$data[$message->topic]["changed"] = time();
$out = file_get_contents(__DIR__ . "/template.json");
$out = preg_replace_callback(
@ -69,7 +68,9 @@ $c->onMessage(function (\Mosquitto\Message $message) use (&$data, $conf) {
if (!is_dir("public")) {
mkdir("public");
}
file_put_contents("public/spaceapi.json", $out);
file_put_contents("public/spaceapi.json.new", $out);
// ensure atomic update
rename("public/spaceapi.json.new", "public/spaceapi.json");
});
$c->connect($conf["mqtt"]["host"]);
$data = [];