amcolash / MMM-json-feed

A MagicMirror module that displays information from any json source
MIT License
17 stars 15 forks source link

Multiple sources #5

Closed Geoffibs closed 6 years ago

Geoffibs commented 6 years ago

Great module, works great on my external esp8266 which sends me data out in json format for pressure, humidity, temperature. This is in a rear garden.

I have the same upstairs but on a different IP address. I can't seem to display the two at once though, they seem to intermingle. Somehow no matter how I format it.

e.g. config: { url: "http://192.168.0.121/json?tasknr=2", title: "Rear Garden feed", values: ["Temperature","Humidity","Pressure"] } Works great, but if I add a second URL (I've used different sensor names too just in case) that's when I have issues.

I've tried adding as a 2nd mmm module but I'm clearly a dope with this. My first go though and really like this module as it's small and neat.

Thanks in advance,

Geoff

amcolash commented 6 years ago

Currently, there was no support for multiple urls at once. What you can do however is add in multiple instances of the module. Note: this method is somewhat hackish and is probably not the best solution long-term if more people need this feature.

Follow these steps for each extra module. We will use X in the below instructions to denote the x-th module (i.e. use 2 for your 2nd module)

$ cd MagicMirror/modules $ git clone https://github.com/amcolash/MMM-json-feed.git MMM-json-feedX - change X accordingly.

Add this to your config/config.js file, change number if needed.

{
    module: 'MMM-json-feedX',
    position: 'position',
    config: {
        // each module has their own config now
    }
},

Rename MagicMirror/modules/MMM-json-feedX/MMM-json-feed.js to MagicMirror/modules/MMM-json-feedX/MMM-json-feedX.js and change line 3 in the file from: Module.register("MMM-json-feed", { to Module.register("MMM-json-feedX", {

That should get you up and running with a 2/3/4/etc instance of the module.

Note: Each version of the module needs to be updated separately. Therefore to update, you will need to do:

$ cd MagicMirror/modules/MMM-json-feed
$ git pull
$ cd MagicMirror/modules/MMM-json-feed2
$ git pull

etc.

Geoffibs commented 6 years ago

My goodness, you're on the ball!

Thanks for responding so quickly, I'll give it a go.

amcolash commented 6 years ago

Glad to help! Hope it worked ok :grinning:

amcolash commented 6 years ago

I wanted to add this feature in for real since it is easy to do and honestly only took a few minutes to do. It does not have support for the titles of the different sources (I think that should stay separate like mentioned in the above workaround). Anyways, use as follows:

urls: [
        'http://your.server.json.here/abc1.json',
        'http://your.server.json.here/abc2.json',
      ]

That is it!