Skip to content

Commit

Permalink
spotfile devided
Browse files Browse the repository at this point in the history
  • Loading branch information
Gunvor Nilsson committed Aug 22, 2019
1 parent 50e6340 commit 3e0f36e
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 84 deletions.
76 changes: 38 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,41 @@

![detta behöver du](http://www.behovsbo.se/themes/images/bbbmaterial.jpg)

| Bom | Antal | Materiallista |
| --- | ------|-------------- |
| 1 | 1 | Raspberry pi 3 modell B |
| 2 | 9 | ds18b20 (1-wire eller dallas) |
| 3 | 1 | micro SD kort, gärna minst 32GB |
| 4 | 1 | reläkort med 8 relän |
| 5 | 1 | 5V 2,1A USB laddare |
| 6 | 1 | kopplingsdäck |
| Bom | Antal | Materiallista |
| --- | ------|---------------------------------- |
| 1 | 1 | Raspberry pi 3 modell B |
| 2 | 9 | ds18b20 (1-wire eller dallas) |
| 3 | 1 | micro SD kort, gärna minst 32GB |
| 4 | 1 | reläkort med 8 relän |
| 5 | 1 | 5V 2,1A USB laddare |
| 6 | 1 | kopplingsdäck |
| 7 | 1 | knippe kopplingssladdar hane-hane |
| 8 | 1 | knippe kopplingssladdar hona-hona |
| 9 | 1 | Ethernetsladd |
| 9 | 1 | Ethernetsladd |

Mjukvaran för styrsystemet är byggt med Node.js, Express, React och Sqlite3.

### Gör så här

- Konfigurera sd-kortet, installera raspbian och konfigurera till svenska förhållanden.
- `https://www.raspberrypi.org/documentation/installation/noobs.md`
- Aktivera ssh.
- Byt lösenord!!!
- Aktivera 1-Wire
- Aktivera spi
- Hämta BehovsBoBoxen med:
- Konfigurera sd-kortet, installera raspbian och konfigurera till svenska förhållanden.
- `https://www.raspberrypi.org/documentation/installation/noobs.md`
- Aktivera ssh.
- Byt lösenord!!!
- Aktivera 1-Wire
- Aktivera spi
- Hämta BehovsBoBoxen med:
```sh
git clone https://github.com/guni12/bbbnode
```
- Öppna `/home/pi/bbbnode/scripts/pass.txt` och ändra lösenordet till ditt eget val
- Kopiera hela ovan kommando och kör det i en terminal
- Kör sedan
- Öppna `/home/pi/bbbnode/scripts/pass.txt` och ändra lösenordet till ditt eget val
- Kopiera hela ovan kommando och kör det i en terminal
- Kör sedan
```sh
sudo sh /home/pi/bbbnode/scripts/install.sh
```
- Efter reboot gå till boxens katalog:
- `cd bbbnode`
- Kör följande kommandon:
- Efter reboot gå till boxens katalog:
- `cd bbbnode`
- Kör följande kommandon:

```sh
npm install
Expand All @@ -47,34 +47,34 @@ sqlite3 texts.sqlite
.read migrate.sqlite
.exit
```
- Gå tillbaka:
- `cd ..`
- Öppna en terminal och kör igång servern:
- Gå tillbaka:
- `cd ..`
- Öppna en terminal och kör igång servern:
```sh
npm start
```
- Installera sensorer:
- Gå in i webbläsaren med `http://localhost/find`
- sedan `http://localhost/init`
- sedan `http://ditt.ip.n.r:8787/zones`
- Bestäm namn på zonerna
- Koppla aktiva relän till zonerna via `http://ip.nr:8787/rpio`
- hämta spotpriser genom ett pythonscript
- Installera sensorer:
- Gå in i webbläsaren med `http://localhost/find`
- sedan `http://localhost/init`
- sedan `http://ditt.ip.n.r:8787/zones`
- Bestäm namn på zonerna
- Koppla aktiva relän till zonerna via `http://ip.nr:8787/rpio`
- hämta spotpriser genom ett pythonscript
```sh
python3 /home/pi/bbbnode/public/scripts/spot/checkfile.py
```
- `http://localhost:1337/tempupdate`
- `http://localhost:1337/hourcontrol`
- öppna ny terminal:
- `http://localhost:1337/tempupdate`
- `http://localhost:1337/hourcontrol`
- öppna ny terminal:
```sh
sudo crontab -l -u root | cat /home/pi/bbbnode/scripts/cron.txt | sudo crontab -u root -
```
- om du vill se vilka processer som är aktiva:
- om du vill se vilka processer som är aktiva:
```sh
sudo lsof -i -P -n | grep LISTEN
```
- för att släcka server-process och göra omstart:
- för att släcka server-process och göra omstart:
```sh
sudo fuser -k 1337/tcp
```
- port forwarding...
- port forwarding...
21 changes: 21 additions & 0 deletions public/javascripts/addHeat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = (function () {
function addHeat(temp) {
let check = false;

for (let i = 0; i < temp.length; i++) {
if (temp[i] === 1 && check === false) {
if (i > 0) {temp[i-1] = 2;}
if (i > 1) {temp[i-2] = 2;}
check = true;
}
if (check === true && temp[i] === 0) {
check = false;
}
}
return temp;
}

return {
addHeat: addHeat
};
}());
49 changes: 5 additions & 44 deletions public/javascripts/extractControls.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
const makelist = require('./hourList');
const adh = require('./addHeat');

module.exports = (function () {
function extractControls(data, settings, isaway) {
let temp = [];
let avg = parseFloat(data['Average']) / 10;
let marker = (settings.percent/10)+1;
let temp = makelist.hourList(data, marker, avg);

for (let i = 1; i < 26; i++) {
let key = i < 3 ? 'Hour' + i : 'Hour' + (i-1);

if (i === 3) {
key = 'Hour' + i + 'A';
temp = isHigh(temp, data, key, marker, avg);
} else if (i === 4) {
key = 'Hour' + (i-1) + 'B';
temp = isHigh(temp, data, key, marker, avg);
} else {
temp = isHigh(temp, data, key, marker, avg);
}
}

temp = addControl(temp);
temp = adh.addHeat(temp);

if (isaway) {
temp.fill(3);
Expand All @@ -29,34 +18,6 @@ module.exports = (function () {
return temp;
}

function isHigh(list, data, key, marker, avg) {
let tl = list;
let price = data[key] === "" ? null : parseFloat(data[key]) / 10;

if (price && ((price * marker) > avg)) {
tl.push(1);
} else {
tl.push(0);
}
return tl;
}

function addControl(temp) {
let check = false;

for (let i = 0; i < temp.length; i++) {
if (temp[i] === 1 && check === false) {
if (i > 0) {temp[i-1] = 2;}
if (i > 1) {temp[i-2] = 2;}
check = true;
}
if (check === true && temp[i] === 0) {
check = false;
}
}
return temp;
}

return {
extractControls: extractControls
};
Expand Down
26 changes: 26 additions & 0 deletions public/javascripts/hourList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const ish = require('./isHigh');

module.exports = (function () {
function hourList(data, marker, avg) {
let temp = [];

for (let i = 1; i < 26; i++) {
let key = i < 3 ? 'Hour' + i : 'Hour' + (i-1);

if (i === 3) {
key = 'Hour' + i + 'A';
temp = ish.isHigh(temp, data, key, marker, avg);
} else if (i === 4) {
key = 'Hour' + (i-1) + 'B';
temp = ish.isHigh(temp, data, key, marker, avg);
} else {
temp = ish.isHigh(temp, data, key, marker, avg);
}
}
return temp;
}

return {
hourList: hourList
};
}());
17 changes: 17 additions & 0 deletions public/javascripts/isHigh.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = (function () {
function isHigh(list, data, key, marker, avg) {
let tl = list;
let price = data[key] === "" ? null : parseFloat(data[key]) / 10;

if (price && ((price * marker) > avg)) {
tl.push(1);
} else if (price) {
tl.push(0);
}
return tl;
}

return {
isHigh: isHigh
};
}());
4 changes: 2 additions & 2 deletions public/scripts/spot/spotprice.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ PR;SO;2019;34;3;21.08.2019;NO2;SEK;356,24;356,67;344,82;;336,42;343,96;364,21;37
PR;SO;2019;34;3;21.08.2019;NO3;SEK;356,24;356,67;344,82;;336,42;343,96;365,93;403,10;411,50;424,21;420,98;409,34;401,80;394,26;388,23;386,18;384,46;387,48;404,71;398,36;398,36;398,14;416,99;393,94;386,40;388,02
PR;SO;2019;34;3;21.08.2019;NO4;SEK;356,24;356,67;344,82;;336,42;343,96;365,93;403,10;411,50;424,21;420,98;409,34;401,80;394,26;388,23;386,18;384,46;387,48;404,71;398,36;398,36;398,14;396,42;392,75;386,40;387,11
PR;SO;2019;34;3;21.08.2019;NO5;SEK;356,24;356,67;344,82;;336,42;343,96;364,21;373,80;376,17;382,09;381,12;379,50;377,89;372,50;367,01;368,62;366,47;369,49;375,20;375,09;374,76;374,01;374,55;373,15;367,22;367,96
PR;SO;2019;34;3;21.08.2019;SE1;SEK;356,24;356,67;344,82;;336,42;343,96;365,93;403,20;411,50;424,21;420,98;409,34;401,80;394,26;388,23;386,18;384,46;387,48;404,71;398,36;398,36;398,14;416,99;393,94;386,40;388,02
PR;SO;2019;34;3;21.08.2019;SE2;SEK;356,24;356,67;344,82;;336,42;343,96;365,93;403,20;411,50;424,21;420,98;409,34;401,80;394,26;388,23;386,18;384,46;387,48;404,71;398,36;398,36;398,14;416,99;393,94;386,40;388,02
PR;SO;2019;34;3;21.08.2019;SE1;SEK;356,24;286,67;284,82;;286,42;303,96;315,93;403,20;411,50;424,21;420,98;409,34;401,80;394,26;388,23;386,18;384,46;387,48;294,71;298,36;298,36;398,14;416,99;393,94;386,40;388,02
PR;SO;2019;34;3;21.08.2019;SE2;SEK;356,24;356,67;324,82;;316,42;303,96;315,93;403,20;411,50;424,21;420,98;409,34;401,80;394,26;388,23;386,18;384,46;387,48;404,71;398,36;398,36;398,14;416,99;393,94;386,40;388,02
PR;SO;2019;34;3;21.08.2019;SE3;SEK;356,24;356,67;344,82;;336,42;343,96;365,93;403,20;411,50;424,21;420,98;409,34;401,80;394,26;388,23;386,18;384,46;387,48;404,71;398,36;398,36;398,14;416,99;393,94;386,40;388,02
PR;SO;2019;34;3;21.08.2019;SE4;SEK;356,24;356,67;344,82;;336,42;343,96;365,93;445,43;614,02;604,43;451,89;409,34;401,80;394,26;388,23;386,18;384,46;387,48;427,01;526,11;701,81;724,54;556,17;393,94;386,40;445,31
AL;72

0 comments on commit 3e0f36e

Please sign in to comment.