Merge pull request #27 from ToSa27/development
Improved documentation and usage of codebender for auto sketch compilation
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
See NodeJsController/Readme.md for usage instructions...
|
||||
|
||||
<h1>Technical details to write your own controller</h1>
|
||||
All initialization the bootloader does (finding parent / requesting nodeId on first start) uses the same packets as a normal MySensors sketch. There is no need for the controller to distinguish between packets from the bootloader and packets from normal sketch execution. The controller only needs to care about two additional request/response communications. All communication is binary.
|
||||
<h2>FirmwareConfig</h2>
|
||||
<ul>
|
||||
<li>the bootloader sends a FirmwareConfigRequest packet to the gateway to request information about the firmware it should execute:
|
||||
<p>
|
||||
typedef struct<br/>
|
||||
{<br/>
|
||||
uint16_t type;<br/>
|
||||
uint16_t version;<br/>
|
||||
} FirmwareConfigRequest;
|
||||
</p>
|
||||
<li>the gateway (the controller) responds with a FirmwareConfigResponse including details about the firmware the sensor should execute:
|
||||
<p>
|
||||
typedef struct<br/>
|
||||
{<br/>
|
||||
uint16_t type;<br/>
|
||||
uint16_t version;<br/>
|
||||
uint16_t blocks;<br/>
|
||||
uint16_t crc;<br/>
|
||||
} FirmwareConfigResponse;
|
||||
</p>
|
||||
</ul>
|
||||
<h2>Firmware</h2>
|
||||
<ul>
|
||||
<li>the bootloader sends a FirmwareRequest packet to the gateway to request a specific subset (block) of the compiled firmware:
|
||||
<p>
|
||||
typedef struct<br/>
|
||||
{<br/>
|
||||
uint16_t type;<br/>
|
||||
uint16_t version;<br/>
|
||||
uint16_t block;<br/>
|
||||
} FirmwareRequest;
|
||||
</p>
|
||||
<li>the gateway (the controller) responds with a FirmwareResponse including the specific block of the compiled firmware:
|
||||
</ul>
|
||||
<p>
|
||||
typedef struct<br/>
|
||||
{<br/>
|
||||
uint16_t type;<br/>
|
||||
uint16_t version;<br/>
|
||||
uint16_t block;<br/>
|
||||
uint8_t data[FIRMWARE_BLOCK_SIZE];<br/>
|
||||
} FirmwareResponse;
|
||||
</p>
|
||||
@@ -1,71 +0,0 @@
|
||||
:100000000C9461000C947E000C947E000C947E0095
|
||||
:100010000C947E000C947E000C947E000C947E0068
|
||||
:100020000C947E000C947E000C947E000C947E0058
|
||||
:100030000C947E000C947E000C947E000C947E0048
|
||||
:100040000C949A000C947E000C947E000C947E001C
|
||||
:100050000C947E000C947E000C947E000C947E0028
|
||||
:100060000C947E000C947E00000000002400270009
|
||||
:100070002A0000000000250028002B0000000000DE
|
||||
:1000800023002600290004040404040404040202DA
|
||||
:100090000202020203030303030301020408102007
|
||||
:1000A0004080010204081020010204081020000012
|
||||
:1000B0000007000201000003040600000000000029
|
||||
:1000C000000011241FBECFEFD8E0DEBFCDBF11E08E
|
||||
:1000D000A0E0B1E0E4E5F4E002C005900D92A030AC
|
||||
:1000E000B107D9F711E0A0E0B1E001C01D92A9303D
|
||||
:1000F000B107E1F70E9418020C9428020C9400004A
|
||||
:1001000087E061E00E94C4016AEF70E080E090E067
|
||||
:100110000E941D0187E060E00E94C4016AEF70E068
|
||||
:1001200080E090E00E941D01089587E061E00E9458
|
||||
:10013000850108951F920F920FB60F9211242F93ED
|
||||
:100140003F938F939F93AF93BF93809104019091BE
|
||||
:100150000501A0910601B0910701309108010196B7
|
||||
:10016000A11DB11D232F2D5F2D3720F02D57019696
|
||||
:10017000A11DB11D209308018093040190930501F6
|
||||
:10018000A0930601B09307018091000190910101B5
|
||||
:10019000A0910201B09103010196A11DB11D8093B0
|
||||
:1001A000000190930101A0930201B0930301BF915C
|
||||
:1001B000AF919F918F913F912F910F900FBE0F9014
|
||||
:1001C0001F901895789484B5826084BD84B5816051
|
||||
:1001D00084BD85B5826085BD85B5816085BDEEE64F
|
||||
:1001E000F0E0808181608083E1E8F0E0108280812E
|
||||
:1001F00082608083808181608083E0E8F0E080819C
|
||||
:1002000081608083E1EBF0E0808184608083E0EBBB
|
||||
:10021000F0E0808181608083EAE7F0E080818460A3
|
||||
:1002200080838081826080838081816080838081FF
|
||||
:10023000806880831092C1000895EF92FF920F931F
|
||||
:100240001F93CF93DF937B018C013FB7F89480918C
|
||||
:10025000000190910101A0910201B091030126B526
|
||||
:10026000A89B05C02F3F19F00196A11DB11D3FBFEE
|
||||
:10027000BA2FA92F982F8827820F911DA11DB11D7C
|
||||
:1002800052E0880F991FAA1FBB1F5A95D1F7EC01A6
|
||||
:1002900030C00E9427023FB7F894809100019091EE
|
||||
:1002A0000101A0910201B091030126B5A89B05C0F0
|
||||
:1002B0002F3F19F00196A11DB11D3FBFBA2FA92FE5
|
||||
:1002C000982F8827820F911DA11DB11D32E0880F44
|
||||
:1002D000991FAA1FBB1F3A95D1F78C1B9D0B885EF7
|
||||
:1002E0009340B8F20894E108F10801091109C851D6
|
||||
:1002F000DC4FE114F1040105110559F6DF91CF91AE
|
||||
:100300001F910F91FF90EF900895CF93DF93482FA7
|
||||
:1003100050E0CA0186569F4FFC0134914A575F4F07
|
||||
:10032000FA018491882369F190E0880F991FFC01FC
|
||||
:10033000E859FF4FA591B491FC01EE58FF4FC591CC
|
||||
:10034000D491662351F42FB7F8948C91932F909504
|
||||
:1003500089238C93888189230BC0623061F42FB785
|
||||
:10036000F8948C91932F909589238C938881832B7B
|
||||
:1003700088832FBF06C09FB7F8948C91832B8C93F2
|
||||
:100380009FBFDF91CF910895482F50E0CA01825559
|
||||
:100390009F4FFC012491CA0186569F4FFC01949106
|
||||
:1003A0004A575F4FFA013491332309F440C02223A6
|
||||
:1003B00051F1233071F0243028F42130A1F02230A3
|
||||
:1003C00011F514C02630B1F02730C1F02430D9F433
|
||||
:1003D00004C0809180008F7703C0809180008F7D62
|
||||
:1003E0008093800010C084B58F7702C084B58F7D64
|
||||
:1003F00084BD09C08091B0008F7703C08091B000A8
|
||||
:100400008F7D8093B000E32FF0E0EE0FFF1FEE58DA
|
||||
:10041000FF4FA591B4912FB7F894662321F48C91E6
|
||||
:100420009095892302C08C91892B8C932FBF0895BE
|
||||
:10043000CF93DF930E94E2000E949500C0E0D0E0DD
|
||||
:100440000E9480002097E1F30E940000F9CF0895F8
|
||||
:04045000F894FFCF4E
|
||||
:00000001FF
|
||||
@@ -1,71 +0,0 @@
|
||||
:100000000C9461000C947E000C947E000C947E0095
|
||||
:100010000C947E000C947E000C947E000C947E0068
|
||||
:100020000C947E000C947E000C947E000C947E0058
|
||||
:100030000C947E000C947E000C947E000C947E0048
|
||||
:100040000C949A000C947E000C947E000C947E001C
|
||||
:100050000C947E000C947E000C947E000C947E0028
|
||||
:100060000C947E000C947E00000000002400270009
|
||||
:100070002A0000000000250028002B0000000000DE
|
||||
:1000800023002600290004040404040404040202DA
|
||||
:100090000202020203030303030301020408102007
|
||||
:1000A0004080010204081020010204081020000012
|
||||
:1000B0000007000201000003040600000000000029
|
||||
:1000C000000011241FBECFEFD8E0DEBFCDBF11E08E
|
||||
:1000D000A0E0B1E0E4E5F4E002C005900D92A030AC
|
||||
:1000E000B107D9F711E0A0E0B1E001C01D92A9303D
|
||||
:1000F000B107E1F70E9418020C9428020C9400004A
|
||||
:1001000086E061E00E94C4016AEF70E080E090E068
|
||||
:100110000E941D0186E060E00E94C4016AEF70E069
|
||||
:1001200080E090E00E941D01089586E061E00E9459
|
||||
:10013000850108951F920F920FB60F9211242F93ED
|
||||
:100140003F938F939F93AF93BF93809104019091BE
|
||||
:100150000501A0910601B0910701309108010196B7
|
||||
:10016000A11DB11D232F2D5F2D3720F02D57019696
|
||||
:10017000A11DB11D209308018093040190930501F6
|
||||
:10018000A0930601B09307018091000190910101B5
|
||||
:10019000A0910201B09103010196A11DB11D8093B0
|
||||
:1001A000000190930101A0930201B0930301BF915C
|
||||
:1001B000AF919F918F913F912F910F900FBE0F9014
|
||||
:1001C0001F901895789484B5826084BD84B5816051
|
||||
:1001D00084BD85B5826085BD85B5816085BDEEE64F
|
||||
:1001E000F0E0808181608083E1E8F0E0108280812E
|
||||
:1001F00082608083808181608083E0E8F0E080819C
|
||||
:1002000081608083E1EBF0E0808184608083E0EBBB
|
||||
:10021000F0E0808181608083EAE7F0E080818460A3
|
||||
:1002200080838081826080838081816080838081FF
|
||||
:10023000806880831092C1000895EF92FF920F931F
|
||||
:100240001F93CF93DF937B018C013FB7F89480918C
|
||||
:10025000000190910101A0910201B091030126B526
|
||||
:10026000A89B05C02F3F19F00196A11DB11D3FBFEE
|
||||
:10027000BA2FA92F982F8827820F911DA11DB11D7C
|
||||
:1002800052E0880F991FAA1FBB1F5A95D1F7EC01A6
|
||||
:1002900030C00E9427023FB7F894809100019091EE
|
||||
:1002A0000101A0910201B091030126B5A89B05C0F0
|
||||
:1002B0002F3F19F00196A11DB11D3FBFBA2FA92FE5
|
||||
:1002C000982F8827820F911DA11DB11D32E0880F44
|
||||
:1002D000991FAA1FBB1F3A95D1F78C1B9D0B885EF7
|
||||
:1002E0009340B8F20894E108F10801091109C851D6
|
||||
:1002F000DC4FE114F1040105110559F6DF91CF91AE
|
||||
:100300001F910F91FF90EF900895CF93DF93482FA7
|
||||
:1003100050E0CA0186569F4FFC0134914A575F4F07
|
||||
:10032000FA018491882369F190E0880F991FFC01FC
|
||||
:10033000E859FF4FA591B491FC01EE58FF4FC591CC
|
||||
:10034000D491662351F42FB7F8948C91932F909504
|
||||
:1003500089238C93888189230BC0623061F42FB785
|
||||
:10036000F8948C91932F909589238C938881832B7B
|
||||
:1003700088832FBF06C09FB7F8948C91832B8C93F2
|
||||
:100380009FBFDF91CF910895482F50E0CA01825559
|
||||
:100390009F4FFC012491CA0186569F4FFC01949106
|
||||
:1003A0004A575F4FFA013491332309F440C02223A6
|
||||
:1003B00051F1233071F0243028F42130A1F02230A3
|
||||
:1003C00011F514C02630B1F02730C1F02430D9F433
|
||||
:1003D00004C0809180008F7703C0809180008F7D62
|
||||
:1003E0008093800010C084B58F7702C084B58F7D64
|
||||
:1003F00084BD09C08091B0008F7703C08091B000A8
|
||||
:100400008F7D8093B000E32FF0E0EE0FFF1FEE58DA
|
||||
:10041000FF4FA591B4912FB7F894662321F48C91E6
|
||||
:100420009095892302C08C91892B8C932FBF0895BE
|
||||
:10043000CF93DF930E94E2000E949500C0E0D0E0DD
|
||||
:100440000E9480002097E1F30E940000F9CF0895F8
|
||||
:04045000F894FFCF4E
|
||||
:00000001FF
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,69 +0,0 @@
|
||||
// Example sketch showing how to send in OneWire temperature readings
|
||||
#include <MySensor.h>
|
||||
#include <SPI.h>
|
||||
#include <DallasTemperature.h>
|
||||
#include <OneWire.h>
|
||||
|
||||
#define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected
|
||||
#define MAX_ATTACHED_DS18B20 16
|
||||
unsigned long WAIT_TIME = 30000; // Wait for feedback from controller after sending and before going to sleep (in milliseconds)
|
||||
unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
|
||||
OneWire oneWire(ONE_WIRE_BUS);
|
||||
DallasTemperature sensors(&oneWire);
|
||||
MySensor gw;
|
||||
float lastTemperature[MAX_ATTACHED_DS18B20];
|
||||
int numSensors=0;
|
||||
boolean receivedConfig = false;
|
||||
boolean metric = true;
|
||||
// Initialize temperature message
|
||||
MyMessage msg(0,V_TEMP);
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Startup OneWire
|
||||
sensors.begin();
|
||||
|
||||
// Startup and initialize MySensors library. Set callback for incoming messages.
|
||||
gw.begin();
|
||||
|
||||
// Send the sketch version information to the gateway and Controller
|
||||
gw.sendSketchInfo("Temperature Sensor", "1.0");
|
||||
|
||||
// Fetch the number of attached temperature sensors
|
||||
numSensors = sensors.getDeviceCount();
|
||||
|
||||
// Present all sensors to controller
|
||||
for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
|
||||
gw.present(i, S_TEMP);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Process incoming messages (like config from server)
|
||||
gw.process();
|
||||
|
||||
// Fetch temperatures from Dallas sensors
|
||||
sensors.requestTemperatures();
|
||||
|
||||
// Read temperatures and send them to controller
|
||||
for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
|
||||
|
||||
// Fetch and round temperature to one decimal
|
||||
float temperature = static_cast<float>(static_cast<int>((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
|
||||
|
||||
// Only send data if temperature has changed and no error
|
||||
if (lastTemperature[i] != temperature && temperature != -127.00) {
|
||||
|
||||
// Send in the new temperature
|
||||
gw.send(msg.setSensor(i).set(temperature,1));
|
||||
lastTemperature[i]=temperature;
|
||||
}
|
||||
}
|
||||
delay(WAIT_TIME);
|
||||
gw.process();
|
||||
gw.sleep(SLEEP_TIME);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
const gwType = 'Ethernet';
|
||||
const gwAddress = '10.0.1.99';
|
||||
const gwPort = 9999;
|
||||
//const gwType = 'Ethernet';
|
||||
//const gwAddress = '10.0.1.99';
|
||||
//const gwPort = 9999;
|
||||
|
||||
//const gwType = 'Serial';
|
||||
const gwType = 'Serial';
|
||||
//const gwPort = 'COM4';
|
||||
//const gwPort = '/dev/ttyUSB0';
|
||||
//const gwBaud = 115200;
|
||||
const gwPort = '/dev/ttyAMA0';
|
||||
const gwBaud = 115200;
|
||||
|
||||
const dbAddress = '127.0.0.1';
|
||||
const dbPort = 27017;
|
||||
const dbName = 'MySensorsDb';
|
||||
|
||||
const fwHexFiles = [ 'BlinkRed.hex', 'BlinkGreen.hex', 'DallasTemperatureSensor.cpp.hex' ];
|
||||
const fwDefaultType = 2; // index of hex file from array above
|
||||
const fwSketches = [ ];
|
||||
const fwDefaultType = 0xFFFF; // index of hex file from array above (0xFFFF
|
||||
|
||||
const FIRMWARE_BLOCK_SIZE = 16;
|
||||
const BROADCAST_ADDRESS = 255;
|
||||
@@ -117,6 +117,8 @@ const P_ULONG32 = 5;
|
||||
const P_CUSTOM = 6;
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var requestify = require('requestify');
|
||||
var appendedString="";
|
||||
|
||||
function crcUpdate(old, value) {
|
||||
@@ -146,76 +148,99 @@ function pushDWord(arr, val) {
|
||||
arr.push((val >> 24) & 0x000000FF);
|
||||
}
|
||||
|
||||
function loadFirmware(fwtype, fwversion, filename, db) {
|
||||
console.log("loading firmware: " + filename);
|
||||
fwdata = [];
|
||||
var start = 0;
|
||||
var end = 0;
|
||||
var pos = 0;
|
||||
var hex = fs.readFileSync(filename).toString().split("\n");
|
||||
for(l in hex) {
|
||||
line = hex[l].trim();
|
||||
if (line.length > 0) {
|
||||
while (line.substring(0, 1) != ":")
|
||||
line = line.substring(1);
|
||||
var reclen = parseInt(line.substring(1, 3), 16);
|
||||
var offset = parseInt(line.substring(3, 7), 16);
|
||||
var rectype = parseInt(line.substring(7, 9), 16);
|
||||
var data = line.substring(9, 9 + 2 * reclen);
|
||||
var chksum = parseInt(line.substring(9 + (2 * reclen), 9 + (2 * reclen) + 2), 16);
|
||||
if (rectype == 0) {
|
||||
if ((start == 0) && (end == 0)) {
|
||||
if (offset % 128 > 0)
|
||||
throw new Error("error loading hex file - offset can't be devided by 128");
|
||||
start = offset;
|
||||
end = offset;
|
||||
function loadFirmware(fwtype, fwversion, sketch, db) {
|
||||
var filename = path.basename(sketch);
|
||||
console.log("compiling firmware: " + filename);
|
||||
var req = {
|
||||
files: [{
|
||||
filename: filename,
|
||||
content: fs.readFileSync(sketch).toString()
|
||||
}],
|
||||
format: "hex",
|
||||
version: "105",
|
||||
build: {
|
||||
mcu: "atmega328p",
|
||||
f_cpu: "16000000L",
|
||||
core: "arduino",
|
||||
variant: "standard"
|
||||
}
|
||||
};
|
||||
requestify.post('https://codebender.cc/utilities/compile/', req).then(function(res) {
|
||||
var body = JSON.parse(res.getBody());
|
||||
if (body.success) {
|
||||
console.log("loading firmware: " + filename);
|
||||
fwdata = [];
|
||||
var start = 0;
|
||||
var end = 0;
|
||||
var pos = 0;
|
||||
var hex = body.output.split("\n");
|
||||
for(l in hex) {
|
||||
line = hex[l].trim();
|
||||
if (line.length > 0) {
|
||||
while (line.substring(0, 1) != ":")
|
||||
line = line.substring(1);
|
||||
var reclen = parseInt(line.substring(1, 3), 16);
|
||||
var offset = parseInt(line.substring(3, 7), 16);
|
||||
var rectype = parseInt(line.substring(7, 9), 16);
|
||||
var data = line.substring(9, 9 + 2 * reclen);
|
||||
var chksum = parseInt(line.substring(9 + (2 * reclen), 9 + (2 * reclen) + 2), 16);
|
||||
if (rectype == 0) {
|
||||
if ((start == 0) && (end == 0)) {
|
||||
if (offset % 128 > 0)
|
||||
throw new Error("error loading hex file - offset can't be devided by 128");
|
||||
start = offset;
|
||||
end = offset;
|
||||
}
|
||||
if (offset < end)
|
||||
throw new Error("error loading hex file - offset lower than end");
|
||||
while (offset > end) {
|
||||
fwdata.push(255);
|
||||
pos++;
|
||||
end++;
|
||||
}
|
||||
for (var i = 0; i < reclen; i++) {
|
||||
fwdata.push(parseInt(data.substring(i * 2, (i * 2) + 2), 16));
|
||||
pos++;
|
||||
}
|
||||
end += reclen;
|
||||
}
|
||||
}
|
||||
if (offset < end)
|
||||
throw new Error("error loading hex file - offset lower than end");
|
||||
while (offset > end) {
|
||||
fwdata.push(255);
|
||||
pos++;
|
||||
end++;
|
||||
}
|
||||
for (var i = 0; i < reclen; i++) {
|
||||
fwdata.push(parseInt(data.substring(i * 2, (i * 2) + 2), 16));
|
||||
pos++;
|
||||
}
|
||||
end += reclen;
|
||||
}
|
||||
var pad = end % 128; // ATMega328 has 64 words per page / 128 bytes per page
|
||||
for (var i = 0; i < 128 - pad; i++) {
|
||||
fwdata.push(255);
|
||||
pos++;
|
||||
end++;
|
||||
}
|
||||
}
|
||||
}
|
||||
var pad = end % 128; // ATMega328 has 64 words per page / 128 bytes per page
|
||||
for (var i = 0; i < 128 - pad; i++) {
|
||||
fwdata.push(255);
|
||||
pos++;
|
||||
end++;
|
||||
}
|
||||
var blocks = (end - start) / FIRMWARE_BLOCK_SIZE;
|
||||
var crc = 0xFFFF;
|
||||
for (var i = 0; i < blocks * FIRMWARE_BLOCK_SIZE; ++i) {
|
||||
var v = crc;
|
||||
crc = crcUpdate(crc, fwdata[i]);
|
||||
}
|
||||
db.collection('firmware', function(err, c) {
|
||||
c.update({
|
||||
'type': fwtype,
|
||||
'version': fwversion
|
||||
}, {
|
||||
$set: {
|
||||
'filename': filename,
|
||||
'blocks': blocks,
|
||||
'crc': crc,
|
||||
'data': fwdata
|
||||
var blocks = (end - start) / FIRMWARE_BLOCK_SIZE;
|
||||
var crc = 0xFFFF;
|
||||
for (var i = 0; i < blocks * FIRMWARE_BLOCK_SIZE; ++i) {
|
||||
var v = crc;
|
||||
crc = crcUpdate(crc, fwdata[i]);
|
||||
}
|
||||
}, {
|
||||
upsert: true
|
||||
}, function(err, result) {
|
||||
if (err)
|
||||
console.log('Error writing firmware to database');
|
||||
});
|
||||
});
|
||||
console.log("loading firmware done. blocks: " + blocks + " / crc: " + crc);
|
||||
db.collection('firmware', function(err, c) {
|
||||
c.update({
|
||||
'type': fwtype,
|
||||
'version': fwversion
|
||||
}, {
|
||||
$set: {
|
||||
'filename': filename,
|
||||
'blocks': blocks,
|
||||
'crc': crc,
|
||||
'data': fwdata
|
||||
}
|
||||
}, {
|
||||
upsert: true
|
||||
}, function(err, result) {
|
||||
if (err)
|
||||
console.log('Error writing firmware to database');
|
||||
});
|
||||
});
|
||||
console.log("loading firmware done. blocks: " + blocks + " / crc: " + crc);
|
||||
} else {
|
||||
console.log("error: %j", res.body);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -645,8 +670,8 @@ dbc.connect('mongodb://' + dbAddress + ':' + dbPort + '/' + dbName, function(err
|
||||
db.createCollection('firmware', function(err, collection) { });
|
||||
|
||||
// ToDo : check for new hex files / only load if new / get type and version from filename
|
||||
for (var i = 0; i < fwHexFiles.length; i++)
|
||||
loadFirmware(i, 1, fwHexFiles[i], db);
|
||||
for (var i = 0; i < fwSketches.length; i++)
|
||||
loadFirmware(i, 1, fwSketches[i], db);
|
||||
|
||||
var gw;
|
||||
if (gwType == 'Ethernet') {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<h1>MySensors with NodeJS Controller and OTA bootloader on RPi</h1>
|
||||
<p>My RPi runs Arduino to compile and flash sketches and the bootloader. With this setup no separate PC/Mac is needed. Exactly the same could be achieved (faster) using a PC/Mac for all the Arduino compilation and flashing activities – just skip the steps and execute on PC/Mac instead.
|
||||
<h2>Hardware</h2>
|
||||
<p>Headless Raspberry Pi model B with wired Ethernet</p>
|
||||
<p>I'm connecting a monitor only for first time boot to get the IP address and then connect via Putty/xRDP</p>
|
||||
@@ -140,8 +139,6 @@ export PATH</p>
|
||||
<li>git checkout development
|
||||
<li>cd NodeJsController
|
||||
<li>npm install
|
||||
<li>nano NodeJsController.js (optional : removing sample firmwares)
|
||||
<p>const fwHexFiles = <font color="#FF0000">[ ]</font>;</p>
|
||||
<li><i>to confirm that the NodeJsController is working as expected and connects to the local mongo DB: "node NodeJsController.js" which should start the controller, connect to the database and run into an error connecting to the gateway. Stop node again via Ctrl-c</i>
|
||||
</ul>
|
||||
<h2>Start NodeJsController on boot</h2>
|
||||
@@ -215,7 +212,7 @@ Arduino RESET <-> Raspberry Pi GPIO22 (pin 15)</p>
|
||||
<font color="#FF0000"><strike>//</strike></font>const gwType = 'Serial';<br/>
|
||||
<font color="#FF0000"><strike>//</strike></font>const gwPort = '<font color="#FF0000">/dev/ttyAMA0</font>';<br/>
|
||||
<font color="#FF0000"><strike>//</strike></font>const gwBaud = 115200;</p>
|
||||
<li>sudo service mysensors restart
|
||||
<li>sudo service mysensors restart (at this point stop/restart doesn't work. use "sudo killall node" followed by "sudo service mysensors start" instead)
|
||||
</ul>
|
||||
|
||||
<h1>Ethernet Gateway</h1>
|
||||
@@ -262,7 +259,7 @@ IPAddress myIp (10, 0, 1, 99);</p>
|
||||
<ul>
|
||||
<li>nano ~/Arduino/NodeJsController/NodeJsController.js
|
||||
<p>const gwAddress = '<font color="#FF0000">10.0.1.99</font>';</p>
|
||||
<li>sudo service mysensors restart
|
||||
<li>sudo service mysensors restart (at this point stop/restart doesn't work. use "sudo killall node" followed by "sudo service mysensors start" instead)
|
||||
</ul>
|
||||
|
||||
<h1>Sensor Node Bootloader</h1>
|
||||
@@ -291,12 +288,12 @@ ISP_MCU = m328p</p>
|
||||
</ul>
|
||||
|
||||
<h1>End-to-End Test</h1>
|
||||
<h2>Add Firmware to Controller</h2>
|
||||
<h2>Add Firmware to Controller (here: DallasTemperatureSensor)</h2>
|
||||
<ul>
|
||||
<li>nano ~/Arduino/NodeJsController/NodeJsController.js
|
||||
<p>const fwHexFiles = [ 'DallasTemperatureSensor.cpp.hex' ];<br/>
|
||||
const fwDefaultType = 0;</p>
|
||||
<li>sudo service mysensors restart
|
||||
<p>const fwHexFiles = [ <font color="#FF0000">'../libraries/MySensors/examples/DallasTemperatureSensor/DallasTemperatureSensor.ino'</font> ];<br/>
|
||||
const fwDefaultType = <font color="#FF0000">0</font>;</p>
|
||||
<li>sudo service mysensors restart (at this point stop/restart doesn't work. use "sudo killall node" followed by "sudo service mysensors start" instead)
|
||||
</ul>
|
||||
<h2>Flash Firmware OTA</h2>
|
||||
<ul>
|
||||
@@ -305,5 +302,5 @@ const fwDefaultType = 0;</p>
|
||||
</ul>
|
||||
<h2>Check functionality</h2>
|
||||
<ul>
|
||||
<li>in addition to watching the log file (tail command above) you can connect to the mongo db using a client (e.g. <a href="http://robomongo.org">Robomongo</a>) and check if new values are written to the database as a real end-to-end test
|
||||
<li>in addition to watching the log file (tail command above) you can connect to the mongo db using a client (e.g. <a href="http://robomongo.org">Robomongo</a>) and check if new values are written to the database as a real end-to-end test once the bootloader finished uploading the firmware
|
||||
</ul>
|
||||
@@ -5,6 +5,7 @@
|
||||
"dependencies": {
|
||||
"mongodb": "~1.4.7",
|
||||
"net": "~1.0.2",
|
||||
"requestify": "^0.1.16",
|
||||
"serialport": "^1.4.5"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user