Files
iot-api/inc/lib/Narodmon.php

36 lines
843 B
PHP

<?php
namespace Rsgrinko\IotApi;
class Narodmon
{
private const API_ENDPOINT = 'http://narodmon.ru/post';
private string $deviceMac;
private array $data = [];
public function __construct(string $deviceMac)
{
$this->deviceMac = $deviceMac;
}
public function add(string $name, int|float $value): self
{
$this->data[$name] = $value;
return $this;
}
public function send()
{
$data = array_merge($this->data, ['ID' => $this->deviceMac]);
$ch = curl_init(self::API_ENDPOINT);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$reply = curl_exec($ch);
curl_close($ch);
}
}