More good changes
This commit is contained in:
parent
c198b2d75e
commit
ddc834d2f3
@ -4,6 +4,9 @@ import { AppContainer } from "react-hot-loader";
|
|||||||
|
|
||||||
import App from "@app/components/App";
|
import App from "@app/components/App";
|
||||||
import { ProvideState, State } from "@app/state";
|
import { ProvideState, State } from "@app/state";
|
||||||
|
import log, { setLogger } from "@common/log";
|
||||||
|
|
||||||
|
setLogger(log.child({ name: "sprinklers3/app" }));
|
||||||
|
|
||||||
const state = new State();
|
const state = new State();
|
||||||
state.start();
|
state.start();
|
||||||
|
@ -11,7 +11,7 @@ export interface IState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class State implements IState {
|
export class State implements IState {
|
||||||
sprinklersApi: ISprinklersApi = new MqttApiClient();
|
sprinklersApi: ISprinklersApi = new MqttApiClient(`ws://${location.hostname}:1884`);
|
||||||
uiStore = new UiStore();
|
uiStore = new UiStore();
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
9
common/logger.ts
Normal file
9
common/logger.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import * as pino from "pino";
|
||||||
|
|
||||||
|
let logger: pino.Logger = pino();
|
||||||
|
|
||||||
|
export function setLogger(newLogger: pino.Logger) {
|
||||||
|
logger = newLogger;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default logger;
|
@ -11,16 +11,17 @@ import {
|
|||||||
SectionRunner,
|
SectionRunner,
|
||||||
SprinklersDevice,
|
SprinklersDevice,
|
||||||
TimeOfDay,
|
TimeOfDay,
|
||||||
} from "@common/sprinklers";
|
} from "./sprinklers";
|
||||||
import { checkedIndexOf } from "@common/utils";
|
import { checkedIndexOf } from "./utils";
|
||||||
|
|
||||||
export class MqttApiClient implements ISprinklersApi {
|
export class MqttApiClient implements ISprinklersApi {
|
||||||
|
readonly mqttUri: string;
|
||||||
client: mqtt.Client;
|
client: mqtt.Client;
|
||||||
connected: boolean;
|
connected: boolean;
|
||||||
devices: { [prefix: string]: MqttSprinklersDevice } = {};
|
devices: { [prefix: string]: MqttSprinklersDevice } = {};
|
||||||
|
|
||||||
constructor() {
|
constructor(mqttUri: string) {
|
||||||
// (this.client as any).trace = (m => console.log(m));
|
this.mqttUri = mqttUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static newClientId() {
|
private static newClientId() {
|
||||||
@ -30,7 +31,7 @@ export class MqttApiClient implements ISprinklersApi {
|
|||||||
start() {
|
start() {
|
||||||
const clientId = MqttApiClient.newClientId();
|
const clientId = MqttApiClient.newClientId();
|
||||||
console.log("connecting to mqtt with client id %s", clientId);
|
console.log("connecting to mqtt with client id %s", clientId);
|
||||||
this.client = mqtt.connect(`ws://${location.hostname}:1884`, {
|
this.client = mqtt.connect(this.mqttUri, {
|
||||||
clientId,
|
clientId,
|
||||||
});
|
});
|
||||||
this.client.on("message", this.onMessageArrived.bind(this));
|
this.client.on("message", this.onMessageArrived.bind(this));
|
||||||
|
@ -3,7 +3,7 @@ import * as webpack from "webpack";
|
|||||||
import * as webpackMiddleware from "webpack-dev-middleware";
|
import * as webpackMiddleware from "webpack-dev-middleware";
|
||||||
import * as webpackHotMiddleware from "webpack-hot-middleware";
|
import * as webpackHotMiddleware from "webpack-hot-middleware";
|
||||||
|
|
||||||
import logger from "../log";
|
import logger from "../../common/logger";
|
||||||
const log = logger.child({ source: "webpack" });
|
const log = logger.child({ source: "webpack" });
|
||||||
|
|
||||||
/* tslint:disable-next-line:no-var-requires */
|
/* tslint:disable-next-line:no-var-requires */
|
||||||
|
@ -1,16 +1,14 @@
|
|||||||
import { Server } from "http";
|
import { Server } from "http";
|
||||||
|
import log, { setLogger } from "../common/logger";
|
||||||
import app from "./app";
|
import app from "./app";
|
||||||
import log from "./log";
|
|
||||||
|
|
||||||
import * as mqtt from "mqtt";
|
setLogger(log.child({ name: "sprinklers3/server" }));
|
||||||
|
|
||||||
const mqttClient = mqtt.connect("mqtt://localhost:1882");
|
import * as mqtt from "../common/mqtt";
|
||||||
mqttClient.on("connect", () => {
|
|
||||||
log.info("mqtt connected");
|
const mqttClient = new mqtt.MqttApiClient("mqtt://localhost:1882");
|
||||||
});
|
|
||||||
mqttClient.on("error", (err) => {
|
mqttClient.start();
|
||||||
log.error("mqtt error: ", err);
|
|
||||||
});
|
|
||||||
|
|
||||||
const server = new Server(app);
|
const server = new Server(app);
|
||||||
|
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
import * as pino from "pino";
|
|
||||||
|
|
||||||
const log = pino();
|
|
||||||
|
|
||||||
export default log;
|
|
@ -6,7 +6,7 @@
|
|||||||
"jsRules": {},
|
"jsRules": {},
|
||||||
"rules": {
|
"rules": {
|
||||||
"no-console": [
|
"no-console": [
|
||||||
false
|
true
|
||||||
],
|
],
|
||||||
"max-classes-per-file": [
|
"max-classes-per-file": [
|
||||||
false
|
false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user