Welcome to the new home of the Cumulus Support forum.

Latest Cumulus release v1.9.4 (build 1099) - Nov 28 2014
Latest Cumulus MX release - v3.0.0 build 3043 Jan 20 2017. See the Wiki for download

Add Extra Temp Value to Interface Page

Discussion of version 3 of Cumulus, which runs on Windows, Linux, and OS X. All Cumulus MX queries in here, please.
Post Reply
Herbaldew
Posts: 84
Joined: Sun 12 Mar 2017 8:33 pm
Weather Station: VP2+
Operating System: Raspbian Stretch
Location: US Mid-Atlantic

Add Extra Temp Value to Interface Page

Post by Herbaldew » Fri 31 Aug 2018 7:57 pm

I just added an extra temp sensor to my VP2 and have been trying to add it's value in a couple places on my interface pages. I see the temp listed as Sensor 1 under the Extra sensors link. I have not succeeded.

After reading many posts, I now wonder, is this even possible with a reasonable amount of effort? I'd rather not spend more time experimenting if it is not.


Thanks

User avatar
steve
Cumulus Author
Posts: 26714
Joined: Mon 02 Jun 2008 6:49 pm
Weather Station: None
Operating System: None
Location: Vienne, France
Contact:

Re: Add Extra Temp Value to Interface Page

Post by steve » Fri 31 Aug 2018 8:31 pm

It's possible, but you'll need to do a bit of work, and it will require some javascript knowledge. If you look at extrasensors.js, you'll see that it gets the extra temperature data with a call to api/extra/temp.json - if you put http://localhost:8998/api/extra/temp.json into your browser (or use the MX IP address rather than localhost from a different computer) you'll see the format of the data returned. The extra sensors page uses a data table to display the result; to display individual values, you'll need to extract them from the returned data and then update a named 'span' in the html with them.
Steve

Herbaldew
Posts: 84
Joined: Sun 12 Mar 2017 8:33 pm
Weather Station: VP2+
Operating System: Raspbian Stretch
Location: US Mid-Atlantic

Re: Add Extra Temp Value to Interface Page

Post by Herbaldew » Sun 02 Sep 2018 3:37 pm

Thanks for the information.

I didn't figure out how to extract just the value of extra sensor 1 from that JSON.

I did figure out a way to put the value under my temp guage on my gauges page. It's ugly behind the scenes but looks nearly the same when viewing my gauge page. I already have Apache running so I can have pop up graphs on my interface pages. I made a htm with nothing but extra temp 1 on it and inserted it as an iframe under my temp gauges in my gauges page. This will have to do until/if I sort how to extract and use just the figure from the JSON.

Thanks again.

Image

User avatar
steve
Cumulus Author
Posts: 26714
Joined: Mon 02 Jun 2008 6:49 pm
Weather Station: None
Operating System: None
Location: Vienne, France
Contact:

Re: Add Extra Temp Value to Interface Page

Post by steve » Sun 02 Sep 2018 4:29 pm

If you show the result of that json data call, I (or someone else more clever than me) should be able to show you the javascript to extract just the single value. It's probably as simple as indexing by zero - data[0] - if it's a simple row which is returned, I can't remember.
Steve

Herbaldew
Posts: 84
Joined: Sun 12 Mar 2017 8:33 pm
Weather Station: VP2+
Operating System: Raspbian Stretch
Location: US Mid-Atlantic

Re: Add Extra Temp Value to Interface Page

Post by Herbaldew » Sun 02 Sep 2018 4:32 pm

Code: Select all

{"data":[["Sensor 1","81.0","°F"],["Sensor 2","0.0","°F"],["Sensor 3","0.0","°F"],["Sensor 4","0.0","°F"],["Sensor 5","0.0","°F"],["Sensor 6","0.0","°F"],["Sensor 7","0.0","°F"],["Sensor 8","0.0","°F"],["Sensor 9","0.0","°F"],["Sensor 10","0.0","°F"]]}

User avatar
steve
Cumulus Author
Posts: 26714
Joined: Mon 02 Jun 2008 6:49 pm
Weather Station: None
Operating System: None
Location: Vienne, France
Contact:

Re: Add Extra Temp Value to Interface Page

Post by steve » Sun 02 Sep 2018 5:06 pm

I think that if you have the above string in a variable called str, and you have an HTML span called extratemp, then the following javascript will do what you want:

Code: Select all

var jsonData = JSON.parse(str);
document.getElementById("extratemp").textContent=Math.trunc(jsonData.data[0][1]);
You can probably use jQuery instead of that second line, which would result in slightly simpler code, but the very nice Bordeaux blanc that I'm drinking is limiting my ability somewhat.
Steve

Herbaldew
Posts: 84
Joined: Sun 12 Mar 2017 8:33 pm
Weather Station: VP2+
Operating System: Raspbian Stretch
Location: US Mid-Atlantic

Re: Add Extra Temp Value to Interface Page

Post by Herbaldew » Wed 05 Sep 2018 4:53 pm

I initially had no luck getting this to do anything and moved on to trying to truncate numbers in my iframe method.

After figuring out how to truncate my numbers using said iframe method of getting extra temp 1 to display I came back to this to try to figure out how to do it "right".

I immediately notice "Math.trunc" which was my big stumbling block with the iframe method. I changed that to "Math.floor" (Math.trunc doesn't work in the version of Internet Explorer I was using to test).

It works perfectly but only if I add this line above the code you supplied:

Code: Select all

var str = {"data":[["Sensor 1","81.0","°F"],["Sensor 2","0.0","°F"],["Sensor 3","0.0","°F"],["Sensor 4","0.0","°F"],["Sensor 5","0.0","°F"],["Sensor 6","0.0","°F"],["Sensor 7","0.0","°F"],["Sensor 8","0.0","°F"],["Sensor 9","0.0","°F"],["Sensor 10","0.0","°F"]]}
Try as I might, I cannot figure out how to get the current JSON data into a string called "str" to use in place of this static data.

If you or anyone else could give me a nudge in the right direction it will be greatly appreciated.


Thanks again

sfws
Posts: 461
Joined: Fri 27 Jul 2012 11:29 am
Weather Station: Customised mix of Fine Offset
Operating System: Tempermental Win. 10 PC
Location: UK

Re: Add Extra Temp Value to Interface Page

Post by sfws » Wed 05 Sep 2018 5:25 pm

(Deleted my suggestion)
Last edited by sfws on Wed 05 Sep 2018 6:45 pm, edited 1 time in total.

User avatar
steve
Cumulus Author
Posts: 26714
Joined: Mon 02 Jun 2008 6:49 pm
Weather Station: None
Operating System: None
Location: Vienne, France
Contact:

Re: Add Extra Temp Value to Interface Page

Post by steve » Wed 05 Sep 2018 5:42 pm

I don’t have my laptop with me so can’t easily look at the interface code to remind myself how it does it, but if you have a look at the javascript for the dashboard page, for example, you’ll see how it calls MX to get the json for its page into a variable.
Steve

sfws
Posts: 461
Joined: Fri 27 Jul 2012 11:29 am
Weather Station: Customised mix of Fine Offset
Operating System: Tempermental Win. 10 PC
Location: UK

Re: Add Extra Temp Value to Interface Page

Post by sfws » Wed 05 Sep 2018 6:44 pm

I believe Steve means look at this:

Code: Select all

// Convert from MX format to realtimeGauges.txt format
    function convertJson(inp) {
        return {
            temp: inp.OutdoorTemp.toString(),
            tempTL: inp.LowTempToday.toString(),
            tempTH: inp.HighTempToday.toString(),
            intemp: inp.IndoorTemp.toString(),
            dew: inp.OutdoorDewpoint.toString(),
            dewpointTL: inp.LowDewpointToday.toString(),
            dewpointTH: inp.HighDewpointToday.toString(),
            apptemp: inp.AppTemp.toString(),
            apptempTL: inp.LowAppTempToday.toString(),
            apptempTH: inp.HighAppTempToday.toString(),
            wchill: inp.WindChill.toString(),
            wchillTL: inp.LowWindChillToday.toString(),
            heatindex: inp.HeatIndex.toString(),
            heatindexTH: inp.HighHeatIndexToday.toString(),
            humidex: inp.Humidex.toString(),
            wlatest: inp.WindLatest.toString(),
            wspeed: inp.WindAverage.toString(),
            wgust: inp.Recentmaxgust.toString(),
            wgustTM: inp.HighGustToday.toString(),
            bearing: inp.Bearing.toString(),
            avgbearing: inp.Avgbearing.toString(),
            press: inp.Pressure.toString(),
            pressTL: inp.LowPressToday.toString(),
            pressTH: inp.HighPressToday.toString(),
            pressL: inp.AlltimeLowPressure.toString(),
            pressH: inp.AlltimeHighPressure.toString(),
            rfall: inp.RainToday.toString(),
            rrate: inp.RainRate.toString(),
            rrateTM: inp.HighRainRateToday.toString(),
            hum: inp.OutdoorHum.toString(),
            humTL: inp.LowHumToday.toString(),
            humTH: inp.HighHumToday.toString(),
            inhum: inp.IndoorHum.toString(),
            SensorContactLost: "0",
            forecast: (inp.Forecast || "n/a").toString(),
            tempunit: inp.TempUnit.substr(inp.TempUnit.length - 1),
            windunit: inp.WindUnit,
            pressunit: inp.PressUnit,
            rainunit: inp.RainUnit,
            temptrend: inp.TempTrend.toString(),
            TtempTL: inp.LowTempTodayTime,
            TtempTH: inp.HighTempTodayTime,
            TdewpointTL: inp.LowDewpointTodayTime,
            TdewpointTH: inp.HighDewpointTodayTime,
            TapptempTL: inp.LowAppTempTodayTime,
            TapptempTH: inp.HighAppTempTodayTime,
            TwchillTL: inp.LowWindChillTodayTime,
            TheatindexTH: inp.HighHeatIndexTodayTime,
            TrrateTM: inp.HighRainRateTodayTime,
            ThourlyrainTH: inp.HighHourlyRainTodayTime,
            LastRainTipISO: inp.LastRainTipISO,
            hourlyrainTH: inp.HighHourlyRainToday.toString(),
            ThumTL: inp.LowHumTodayTime,
            ThumTH: inp.HighHumTodayTime,
            TpressTL: inp.LowPressTodayTime,
            TpressTH: inp.HighPressTodayTime,
            presstrendval: inp.PressTrend.toString(),
            Tbeaufort: inp.HighBeaufortToday,
            TwgustTM: inp.HighGustTodayTime,
            windTM: inp.HighWindToday.toString(),
            bearingTM: inp.HighGustBearingToday.toString(),
            timeUTC: "",
            BearingRangeFrom10: inp.BearingRangeFrom10.toString(),
            BearingRangeTo10: inp.BearingRangeTo10.toString(),
            UV: inp.UVindex.toString(),
            UVTH: inp.HighUVindexToday.toString(),
            SolarRad: inp.SolarRad.toString(),
            SolarTM: inp.HighSolarRadToday.toString(),
            CurrentSolarMax: inp.CurrentSolarMax.toString(),
            domwinddir: inp.DominantWindDirection.toString(),

User avatar
steve
Cumulus Author
Posts: 26714
Joined: Mon 02 Jun 2008 6:49 pm
Weather Station: None
Operating System: None
Location: Vienne, France
Contact:

Re: Add Extra Temp Value to Interface Page

Post by steve » Wed 05 Sep 2018 7:21 pm

Shouldn’t need to do that conversion, as it can be used in json format in this case. It’s simply the call to get the data using the URL that’s needed, and I just can’t remember how it’s done - probably uses ajax.
Steve

Post Reply