0

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);
                });
            })
        });
    }
WhatsYourFunction
  • 621
  • 1
  • 9
  • 25
  • It the temperature sensors are on two different ESP8266s and each one works individually then it's not an I2C problem, it's an issue with "Johnny Five" and its communication with the ESP8266s. – romkey May 16 '19 at 00:11
  • That's interesting. The problem could just as easily by my misunderstanding of J5. If look carefully, there's nothing in the `new five.Thermometer({controller:"MCP9808"})` that connects it to its respective board. I'd like to think the solution is a parameter in addition to 'controller' that would make that connection. – WhatsYourFunction May 16 '19 at 01:02
  • I don't know J5 or I'd be happy to help. – romkey May 16 '19 at 14:38

1 Answers1

0

SOLUTION

There is a board property (undocumented as of this post) under the J5's Thermometer API. Assigning the Board instance in question to that property associates the Thermometer instance with that board.

By way of example the above code would be edited as follows...

    ThisThermometer.Controller=new five.Thermometer({
       board: ThisThermometer.Board, //<-- the missing magic
       controller:"MCP9808"
    });

Thanks to Donovan Buck for figuring this out. May be documented soon.

WhatsYourFunction
  • 621
  • 1
  • 9
  • 25