Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
## TODO update with latest


- [ ] Create clean table structure and files structure

```
events
status - optimized what we save every interval? Start with saving it all.
debug - save everything evey tick. Can be blown away at any time.
```

- [ ] Make observable grill status a dir, and break out individual observables which can be tested with marbles.
- [ ] Subsribers very leightweight, connect to logging or to datastore events.
- [ ] Add a unit test to demo a hex / message into an expected grill status, so we can make sure we are storing the right data to do this in future.


Then

- [ ] Update chart to visualize events (mark series) and status (line charts)


---------


- [x] knowing each socket connection is different we need to refactor that a bit. Create a socket for pinging status, and in sendCommand create a new socket each time and listen for its response.
- [ ] Use sendGrillCOmmandOnce for polling. Make async. Create grill status still in service.
- Seems to have other errors with this - not sure if its better to open one long polling or to keep opening many shot polls.


- [ ] Capture other grill errors? See https://github.com/Aenima4six2/gmg/commit/614589cf775422e394f4529b4befbe8ac33bbdf0


## Structure

This project is based on structure in this article: https://softwareontheroad.com/ideal-nodejs-project-structure/. A quick read over will help you better navigate this project.


## Command API

Command api allows for remote control of your GMG. A few implementation notes
Expand Down Expand Up @@ -123,3 +159,24 @@ rvictl -x ##
GET /cook
// returns all cooks



## OLD database notes

- `brew install rethinkdb`
- `rethinkdb`
- in browser go to http://localhost:8080/

https://marmelab.com/blog/2019/09/25/couchdb_pouchdb_serious_firebase_alternative.html


Good article on optimization
https://www.mongodb.com/blog/post/time-series-data-and-mongodb-part-2-schema-design-best-practices


Filtering changes
https://pouchdb.com/api.html#filtered-changes


Better doc IDS that have our sensor prop names in them?
https://pouchdb.com/2014/06/17/12-pro-tips-for-better-code-with-pouchdb.html
22 changes: 0 additions & 22 deletions README_database.md

This file was deleted.

5 changes: 4 additions & 1 deletion __mocks__/dgram.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
module.exports = { createSocket: jest.fn() };
import { EventEmitter } from 'events';


module.exports = { createSocket: new EventEmitter() };
8 changes: 8 additions & 0 deletions __mocks__/pouchdb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = jest.fn(() => ({
put: () => {
return new Promise(() => true)
},
allDocs: () => {
return new Promise(() => true)
},
}));
File renamed without changes.
File renamed without changes.
9 changes: 6 additions & 3 deletions routes/settings.js → api/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@ import requireCode from "../middleware/requireCode";
import sendCommand from "../middleware/sendCommand";
import jsonCommandSuccessMsg from "../middleware/jsonCommandSuccessMsg";
import { HEX_COMMANDS } from "../constants";
import { latestStatus } from "../grill-polling";
import observableGrillStatus from "./../services/observableGrillStatus";

const router = express.Router();

router.get(
"/pizza",
requireCode,
sendCommand(() => HEX_COMMANDS.setPizzaMode(latestStatus().settings), "hex"),
sendCommand(
() => HEX_COMMANDS.setPizzaMode(observableGrillStatus.value.settings),
"hex"
),
jsonCommandSuccessMsg("pizza mode")
);

router.get(
"/regular",
requireCode,
sendCommand(
() => HEX_COMMANDS.setRegularMode(latestStatus().settings),
() => HEX_COMMANDS.setRegularMode(observableGrillStatus.value.settings),
"hex"
),
jsonCommandSuccessMsg("regular mode")
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import express from "express";

import { temp, power, settings } from "./routes";
import { temp, power, settings } from "./api";

const app = express();

Expand Down
4 changes: 0 additions & 4 deletions config.js

This file was deleted.

3 changes: 3 additions & 0 deletions config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const IP = "192.168.86.140";
export const PORT = 8080;
export const INTERVAL = 2000;
13 changes: 13 additions & 0 deletions constants/csv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const HEADERS = [
"timestamp",
"state",
"isOn",
"currentGrillTemp",
"desiredGrillTemp",
"currentProbe1Temp",
"desiredProbe1Temp",
"currentProbe2Temp",
"desiredProbe2Temp",
"fanModeActive",
"lowPelletAlarmActive",
];
3 changes: 3 additions & 0 deletions constants/emitter-events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// @todo remove, not needed?
export const NEW_GRILL_EVENT = 'NEW_GRILL_EVENT';
export const NEW_GRILL_STATUS = 'NEW_GRILL_STATUS';
41 changes: 9 additions & 32 deletions constants.js → constants/grill-commands.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
export const HEADERS = [
"timestamp",
"state",
"isOn",
"currentGrillTemp",
"desiredGrillTemp",
"currentProbe1Temp",
"desiredProbe1Temp",
"currentProbe2Temp",
"desiredProbe2Temp",
"fanModeActive",
"lowPelletAlarmActive",
];
String.prototype.replaceAt = function (index, replacement) {
return (
this.substr(0, index) +
replacement +
this.substr(index + replacement.length)
);
};

export const COMMANDS = Object.freeze({
powerOn: "UK001!",
Expand All @@ -25,30 +19,13 @@ export const COMMANDS = Object.freeze({
// setRegularMode: 'UC.+ 9 !'
});

String.prototype.replaceAt = function (index, replacement) {
return (
this.substr(0, index) +
replacement +
this.substr(index + replacement.length)
);
};

export const HEX_COMMANDS = Object.freeze({
setPizzaMode: (settings) => {
const mode = `55430${settings.replaceAt(1, '2')}21`;
const mode = `55430${settings.replaceAt(1, "2")}21`;
return mode;
},
setRegularMode: (settings) => {
const mode = `55430${settings.replaceAt(1, '0')}21`;
const mode = `55430${settings.replaceAt(1, "0")}21`;
return mode;
},
});

// UN - what does this do?
// UF150
// Uf150


// used to work
// 5543052b023220202020
// 52b14321919191921
5 changes: 5 additions & 0 deletions constants/grill-events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const POWER_ON = "POWER_ON";
export const POWER_ON_COLDSMOKE = "POWER_ON_COLDSMOKE";
export const FAN_MODE = "FAN_MODE";
export const POWER_OFF = "POWER_OFF";
export const PROBE_DESIRED_CHANGE = "PROBE_DESIRED_CHANGE";
10 changes: 10 additions & 0 deletions constants/grill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const GRILL_NOT_SURE_MAP = {
0: "Climate ICY",
4: "Climate COLD",
8: "Climate AVERAGE",
12: "Climate WARM",
1: "Climate HOT",
10: "Lock temp display OFF",
9: "Auto Revert Wifi OFF",
11: "Auto Revert Wifi ON",
};
12 changes: 12 additions & 0 deletions constants/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { COMMANDS, HEX_COMMANDS } from "./grill-commands";
import * as GRILL_EVENTS from "./grill-events";
import * as EMITTER_EVENTS from "./emitter-events";
import { GRILL_NOT_SURE_MAP } from "./grill";

export {
COMMANDS,
HEX_COMMANDS,
GRILL_EVENTS,
GRILL_NOT_SURE_MAP,
EMITTER_EVENTS,
};
9 changes: 0 additions & 9 deletions data/brisket2.csv

This file was deleted.

18 changes: 14 additions & 4 deletions datastore-pouch.js → datastore/pouch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,33 @@ var PouchDB = require("pouchdb");
const uuid = require("uuid/v4");

const db = new PouchDB("http://localhost:5984/api_test_1");

export async function setup() {}
const eventsDb = new PouchDB("http://localhost:5984/events_test_1");

export async function add(item) {
return await db
.put({ _id: `${item.timestamp}`, ...item })
.then(null, (err) => console.error(err));
}

export async function last() {}
export async function lastKnownStatus() {
return await db
.allDocs({ include_docs: true, limit: 1, descending: true })
.then((data) => data.rows.length ? data.rows[0] : null);
}

export async function all() {
return await db
.allDocs({ include_docs: true, limit: 100, descending: true })
.then((data) => data.rows.map(({ doc }) => doc).reverse());
}

export async function addEvent(item) {
console.log('addEvent', item);
const _id = `${item.timestamp || new Date().getTime()}-${item.type}`
return await eventsDb
.put({ _id, ...item })
.then(null, (err) => console.error(err));
}

/**
* const PouchDB = require("pouchdb");
Expand All @@ -44,4 +54,4 @@ export async function all() {
.catch(err => console.error(err));
}

*/
*/
68 changes: 0 additions & 68 deletions grill-polling.js

This file was deleted.

7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { pollStatus } from "./grill-polling";
import './subscribers/grillStatus';
// import './subscribers/process';
import { grillPollStatus } from "./services/grillPollStatus";

const app = require("./app.js");

pollStatus();
// @TODO start polling here
grillPollStatus();

app.listen(3000, function () {
console.log("Example app listening on port 3000!");
Expand Down
Loading