Enables H4Plugins library to log events to an external MySQL server. See the [example sketch](LINK T.B.A)
The code opens an http port on 8266 and services POST requests in application/x-www-form-urlencoded
format. It expects a MySQL schema called h4
with a table event
with the following DDL:
CREATE TABLE `event` (
`id` int NOT NULL AUTO_INCREMENT,
`ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`device` varchar(16) NOT NULL,
`type` int NOT NULL,
`source` varchar(16) DEFAULT NULL,
`msg` varchar(128) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id_UNIQUE` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10856 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
The POST body must contain data for the following fields:
device
type
source
msg
A server running
- MySQL configured for remote access
- NodeJS
- express
Installation of a suitable OS and the above packages is beyond the scope of this document.
- Create a database named h4 in MySQL
- Create the schema shown above
- Install the nodejs package @mysql/xdevapi
- Edit h4.js and replace the XXXXs with your MySQL username and password
- Ensure your firewall allows inbound HTTP on port 8266
- Start the server with
node h4
- Run the [H4P_RemoteLogger example]( LINK tba) after editing the url with the domain name or IP address of your server
(c) 2021 Phil Bowles h4plugins@gmail.com