Linux Memory vs real memory & MQTT version

Forgot one thing鈥

Here is some code for the MQTT version - I saw it was displayed as 鈥渘/a鈥. I could not figure out how to plug it into the admin_main_view.php code.

mosquitto -h | grep -oP '(?<=mosquitto\sversion\s)[0-9.]+(?=\s*\(build)'

Hi Jon,

Nice fixes. I see you have included Andy in your message text but he does not seem to be included in this PM.

Submitted a file change proposal via Github is not difficult. The easiest way is just to edit the file directly on github: Editing files - GitHub Docs

Please, could you do this to submit a pull-request since there it鈥檚 easy for me to change the wrong bit etc. Github is amazingly useful, it鈥檚 well worth trying to get acquainted with it.

Mosquitto version in Emoncms admin will be super useful, this has been a recent topic since a mosquitto update broke the emonPi implementation: Mosquitto not starting after emonSD update & upgrade. It would be great if users could easily see which version their running.

Thanks again, really appreciate your help.

At the bottom of my first post I see this:


And it includes Andy so I think he is part of this PM.

Thanks for the github link, I鈥檒l read thru it!

In a post many month ago you had mentioned the emonPi updates come from the stable version of emoncms. So I normally watch and review the stable version. But I noticed there are four Branches so I wasn鈥檛 sure what Branch to modify.

I also looked at a few other repositories and did not see a branch named stable and became confused about the overall process for repositories.

Wops, your right. Sorry @Andy_Taylor, I didn鈥檛 spot you!

Correct, emonPi pull from stable however all changes should be made to master then I can review and eventually when stable and tested release periodically into stable which usually includes an Emoncms version number bump.

There is only a stable branch on emoncms core. The emonPi pull from the master branch on the other repos e.g dashboard etc. Ideally we should have a stable branch on all repos, however, the core is the most actively developed and has the greatest chance of breaking stuff if a bug gets committed!

got it! Thank you!

Glyn - all of the changes and testing were done directly on the emonPi and directly in the admin_main_view.php file.

I鈥檝e done the git fork and made the same changes (I hope) to the forked admin_main_view.php file.

Now I want to test it one more time before doing the PR. How do I get my fork loaded into my emonPi to test my git changes?

Nice! I鈥檝e created a PR by viewing your branch on gh.com and clicking create-PR.

The command line instructions at the bottom of the PR page show you how to 鈥榗heckout鈥 the PR to test:

First make your emonpi RW:

$ rpi-rw

Ensure your running latest master branch (not sure if this is needed but won鈥檛 hurt)

$ cd /var/www/emoncms
$ git checkout master 
$ git pull origin master

Then checkout your branch

$ git checkout -b JonMurphy-patch-1 master
$ git pull https://github.com/JonMurphy/emoncms.git patch-1

When your done you can revert back to master (or stable) with:

$ git checkout master

or

$ git checkout stable

$ rpi-ro


Please also make a PR for the Mosquitto version, this will be super useful :thumbsup:

Thanks :slight_smile:

Thank you!! I鈥檝e been reading about github much of the day and I could not figure this out.

Let me test with the Mosquito within the PHP file. I created it via the Terminal and I have no clue if it works within PHP.

Glyn -

The code in the PR is not correct. I forgot to re-calculate the 鈥淔ree:鈥 memory. Do not commit it.

The current code in my github will display Linux memory and real memory:

I am not sure if this will meet chaveiro concerns. Let me know what you鈥檇 prefer.

https://github.com/JonMurphy/emoncms/blob/2569988452cb547b393890e1e3efb8d0ae9d32ba/Modules/admin/admin_main_view.php

Also I cannot get the MQTT version command to work within PHP. The single quotes are giving me problems. Need to find someone with PHP skills!

@Andy_Taylor help!!

mosquitto -h | grep -oP '(?<=mosquitto\sversion\s)[0-9.]+(?=\s*.build)'

I鈥檝e been deliberately not joining this thread, because if I just solved your problem, you wouldn鈥檛 have tried :slight_smile:
@Jon - it鈥檚 great to see you having a go and sharing back to the community, don鈥檛 give in.

My Pi is currently spread all over my desk (been working on another Pi related project this week) - I鈥檒l stick it back together and see if we can鈥檛 get this going for you鈥

1 Like

@Jon @glyn.hudson

Jon - your version code for Mosquitto was very good - I pretty much used that exactly in the pull request just submitted, it needed wrapping up in PHP - but I used pretty much exactly what you submitted as the basis for the code (you should be able to see my PR on GitHub here: Update admin_main_view.php by AndyTaylorTweet 路 Pull Request #578 路 emoncms/emoncms 路 GitHub - feel free to take a look.

Also your suggestions about the RAM use are spot on, rather than show RAM used with buffers / cache and without buffers / cache, I believe its more use to all of us to only show the figure without buffers / cache included, since that is what we鈥檙e all actually interested in, so I just modified the current graph rather than adding a new one.

Glyn - PR submitted for the changes, due to the use of Grep etc the mosquito versioning is going to be limited to Linux / unix hosts, so there is some detection wrapped around that, Windows hosts will get the old N/A and linux hosts will get the version pulled so long as the binary is where its expected to be (that is also tested).

Happy coding friday everyone鈥

1 Like

Andy - thank you!

So how do I load your code at Update admin_main_view.php by AndyTaylorTweet 路 Pull Request #578 路 emoncms/emoncms 路 GitHub? Glyn mentioned to do this for my code:

git checkout -b JonMurphy-patch-1 master
git pull https://github.com/JonMurphy/emoncms.git patch-1

but I cannot figure out the checkout and pull for your code (still learning!)

It was fun figuring out the Memory side and I did learn. But the exec command with the mosquitto -h command was giving me fits!

I created a small PHP file and tried any and all exec commands I could find but I kept getting errors like this:

PHP Parse error:  syntax error, unexpected '(' in /home/pi/data/myApps/mqttver.php on line 4
PHP Notice:  Array to string conversion in /home/pi/data/myApps/mqttver.php on line 6
PHP Parse error:  syntax error, unexpected ';' in /home/pi/data/myApps/mqttver.php on line 6
sh: 1: mosquitto -h | grep -oP '(?<=mosquitto\sversion\s)[0-9.]+(?=\s*.build)': not found
PHP Parse error:  syntax error, unexpected 'echo' (T_ECHO) in /home/pi/data/myApps/mqttver.php on line 5
sh: 1: /usr/sbin/mosquitto -h: not found

(no need to explain any of my errors I just included them as an example)

Thank you again! Jon

You can pull my branch from here:

$ git pull https://github.com/AndyTaylorTweet/emoncms.git master

Your issues with executing your command line relate to the use of quotes.

in PHP to run something on the command line and return the results you will use 鈥渆xec鈥.

Something like <?php exec ('whoami'); ?> would return the user running the command on the command line.

so since you already have quotes in your command, you would need to 鈥渆scape鈥 those quotes in order for them to be passed to the command line rather than PHP interpreting them.

Depending on how much programming you have ever done, this will either make complete sense, or you will be left with a feeling of 鈥渨hat the hell does this mean鈥.

If you are at the latter of those, do a little googling, and then ask any questions you have.

Andy

Thank you! Yes, I do understand escaping a character or quote (and it took a while to sink in!). I did try escaping quotes but it didn鈥檛 work

@exec('mosquitto -h | grep -oP \''(?<=mosquitto\sversion\s)[0-9.]+(?=\s*\(build)'\'', $mqtt_version);

Also - Line 284 needs a quick update (I did the same thing):

from

echo 鈥Total: 鈥.formatSize($system[鈥榤em_info鈥橾[鈥楳emTotal鈥橾).鈥 Used: 鈥.formatSize($sysRamUsed).鈥 Free: 鈥.formatSize($system[鈥榤em_info鈥橾[鈥楳emFree鈥橾).鈥漒n鈥;

to

echo 鈥Total: 鈥.formatSize($system[鈥榤em_info鈥橾[鈥楳emTotal鈥橾).鈥 Used: 鈥.formatSize($sysRamUsed).鈥 Free: 鈥.formatSize($system[鈥榤em_info鈥橾[鈥楳emTotal鈥橾 - $sysRamUsed).鈥漒n鈥;

Goot catch - I was so wrapped up in sorting out the graph that I forgot to fix up the text.

Changes applied in my branch and the PR also updated. - Please re-test.

it is a match and we are good to go! Thank you again!

[email protected]:/var/www/emoncms $ free -m
             total       used       free     shared    buffers     cached
Mem:           973        860        112         43         13        602
-/+ buffers/cache:        244        728
Swap:            0          0          0
[email protected]:/var/www/emoncms $ 

Nice work guys, thanks for instigating @Jon and thanks for helping @Andy_Taylor.

I have merged @Andy_Taylor PR, since this contained the OS check code:

Ignore the face this PR failed the Travis test, this was due to today鈥檚 events in the US. Stay safe out there :confused:: Update admin_main_view.php by AndyTaylorTweet 路 Pull Request #578 路 emoncms/emoncms 路 GitHub

BTW this thread has now been made public for future ref by all :slight_smile:

A post was split to a new topic: Admin display currently installed Emoncms modules