I'm trying figure out how to control multiple temperature sensors.
THE SETUP:
- 2 ESP8266 Micro Controllers
- 2 MCP9808 Temperature Sensors
- 1 Machine controlling both ESPs using Johnny-Five.
NOTE: Each ESP8266 micro controller handles one MCP9808 Temperature Sensor.
THE GOAL: The central machine (MacOS running Johnny-Five) handles both microcontrollers under one Node JS script.
THE PROBLEM: I can control one Micro Controller / Temperature pairing, but not both under the same script. Apparently the key to handling both at once lies in knowing how to handle the IC2 addressing. So far I haven't been able to find any pages, forums, instructions or combinations thereof that clearly explain the logic in terms that I can understand.
THE QUESTION: How to handle I2C using Johnny-Five to control multiple devices
THE CODE: It only works when handling one Sensor, not both In other words with the 4th line commented out it works. Uncommented, it doesn't.
var five = require("johnny-five");
var {EtherPortClient}=require("etherport-client");
var Thermometers=[
//{Name:"Thermometer1", Ip:"192.168.1.101"}, //Uncommenting causes fail.
{Name:"Thermometer2", Ip:"192.168.1.102"}
];
TrackThermometers();
function TrackThermometers(){
Thermometers.forEach(function(ThisThermometer, ThermometerCount){
ThisThermometer.Board=new five.Board({
port: new EtherPortClient({
host: ThisThermometer.Ip,
port: 3030
}),
repl: false
});
ThisThermometer.Board.on("ready", function(){
ThisThermometer.Controller=new five.Thermometer({ //This cmd triggers the error
controller:"MCP9808"
});
ThisThermometer.Controller.on("change", function(){
console.log(this.id, this.fahrenheit);
});
})
});
}