• Categories
  • Recent
  • Tags
  • Popular
  • Register
  • Login
  • Categories
  • Recent
  • Tags
  • Popular
  • Register
  • Login

MyController agent for Raspberry PI

Scheduled Pinned Locked Moved General Discussion
raspberry piagentmycontroller
24 Posts 6 Posters 13.0k Views 3 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    jkandasa
    last edited by 11 Aug 2016, 14:35

    Hello every one,

    I started to develop agent for raspberry pi to monitor and control from MyController. I pushed first draft code on https://github.com/mycontroller-org/mcagent-rpi Communication between Raspberry PI agent(mcagent) and MyController via MQTT.

    If you are interested to test this feature please let me know.
    For now we can do the following actions,

    External:
    • ON/OFF any GPIO pin (relay control)
    • Make a pin as switch (Listen GPIO pin and report to controller)
    Internal:
    • Monitor system memory(RAM) usage
    • Monitor CPU Voltage
    • Monitor CPU temperature

    I'm ready to add more device support in Raspberry PI, If you have idea please let me know.

    IMPORTANT: This is very initial state of agent design, We may change complete concept before actual release.

    NOTE: You should use latest version of MyController from Google-Drive to use raspberry PI agent.

    Thank you!

    H 1 Reply Last reply 17 Jun 2017, 04:47 Reply Quote 0
    • W Offline
      WarLion
      last edited by 28 Nov 2016, 07:18

      What about c.h.I.p. https://getchip.com/pages/chip this can be the best solution for Mycontroller

      J 1 Reply Last reply 28 Nov 2016, 08:01 Reply Quote 0
      • J Offline
        jkandasa @WarLion
        last edited by 28 Nov 2016, 08:01

        @WarLion Yes, May be. But I do not have any C.H.I.P hardware to test.

        1 Reply Last reply Reply Quote 0
        • H Offline
          hqm @jkandasa
          last edited by 17 Jun 2017, 04:47

          @jkandasa said:

          Hello every one,

          I started to develop agent for raspberry pi to monitor and control from MyController. I pushed first draft code on https://github.com/mycontroller-org/mcagent-rpi Communication between Raspberry PI agent(mcagent) and MyController via MQTT.

          If you are interested to test this feature please let me know.
          For now we can do the following actions,

          External:
          • ON/OFF any GPIO pin (relay control)
          • Make a pin as switch (Listen GPIO pin and report to controller)
          Internal:
          • Monitor system memory(RAM) usage
          • Monitor CPU Voltage
          • Monitor CPU temperature

          I'm ready to add more device support in Raspberry PI, If you have idea please let me know.

          IMPORTANT: This is very initial state of agent design, We may change complete concept before actual release.

          NOTE: You should use latest version of MyController from Google-Drive to use raspberry PI agent.

          Thank you!

          Is there any documentation for setup both mcagent and mycontroller ?

          J 1 Reply Last reply 19 Jun 2017, 05:43 Reply Quote 0
          • T Offline
            Tag MOD
            last edited by 18 Jun 2017, 20:08

            @hqm said:

            o add more device support in Raspberry PI, If you have idea please let me know.

            WIll this also work on the orangepi? :).... that would be great!!

            J 1 Reply Last reply 19 Jun 2017, 05:43 Reply Quote 0
            • J Offline
              jkandasa @hqm
              last edited by 19 Jun 2017, 05:43

              @hqm There is no document yet. I will create one soon. Thank you!

              1 Reply Last reply Reply Quote 0
              • J Offline
                jkandasa @Tag
                last edited by 19 Jun 2017, 05:43

                @Tag I do not have any OrangePI. Have to check it there.

                T 1 Reply Last reply 26 Jun 2017, 14:54 Reply Quote 0
                • T Offline
                  Tag MOD @jkandasa
                  last edited by Tag 26 Jun 2017, 14:54

                  @jkandasa said:

                  I do not have any OrangePI. Have to check it there.

                  Thx!
                  (me personally am just interested in the server stats, CPU/RAM, no need for GPIO control)
                  I will test on Orange Pi and keep you posted

                  • does not work....
                    in the log i see this:

                  Unable to determine hardware version. I see: Hardware : sun8i

                  • expecting BCM2708, BCM2709 or BCM2835.
                    If this is a genuine Raspberry Pi then please report this
                    to projects@drogon.net. If this is not a Raspberry Pi then you
                    are on your own as wiringPi is designed to support the
                    Raspberry Pi ONLY.

                  [http://www.orangepi.org/Docs/WiringPi.html](link url) is the wiringPI lib for orange pi

                  [https://github.com/Pi4J/pi4j/tree/master/pi4j-example/src/main/java/orangepi](link url) Seems to be the link to PI4J the orange pi version...Maybe the above info helps

                  J 1 Reply Last reply 27 Jun 2017, 16:13 Reply Quote 0
                  • J Offline
                    jkandasa @Tag
                    last edited by 27 Jun 2017, 16:13

                    @Tag Thanks for the links. Let me update to the latest version of PI4J and let you know.

                    T 1 Reply Last reply 1 Jul 2017, 09:40 Reply Quote 0
                    • T Offline
                      Tag MOD @jkandasa
                      last edited by Tag 7 Feb 2017, 01:49 1 Jul 2017, 09:40

                      @jkandasa

                      Thx!,
                      Will keep an eye open for a new release!

                      Just in the mean time, how to fill a variable from a file?, i have tried to get this using jscript however i am not a java programmer...

                      i.e, ont the OrangePI in armbianthe cpu temp is stored here:

                      /sys/class/thermal/thermal_zone0/temp
                      

                      and here is the cpu frequency

                      /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq 
                      

                      Another nice one would be the memory usage:

                      /sys/fs/cgroup/memory/memory.usage_in_bytes
                      

                      would it be possible to read these in a script and add them to the database?

                      Thx!

                      J 2 Replies Last reply 2 Jul 2017, 16:53 Reply Quote 0
                      • J Offline
                        jkandasa @Tag
                        last edited by 2 Jul 2017, 16:53

                        @Tag I hope it is possible. Let me try this and update you.

                        T 1 Reply Last reply 2 Jul 2017, 18:04 Reply Quote 0
                        • T Offline
                          Tag MOD @jkandasa
                          last edited by 2 Jul 2017, 18:04

                          @jkandasa

                          Thank you!!
                          Running Mycontroller for almost 2 years now, still the best controller out there!!

                          1 Reply Last reply Reply Quote 0
                          • skywatchS Offline
                            skywatch
                            last edited by jkandasa 7 May 2017, 17:16 5 Jul 2017, 10:33

                            No joy yet.....the lig file is full of this message.....

                            2017-07-05 11:26:29,952 ERROR [Thread-4] [org.mycontroller.agent.rpi.mqtt.RpiMqttClient:82] Unable to connect with MQTT broker [tcp://localhost:1883], Reason Code: 4,
                            org.eclipse.paho.client.mqttv3.MqttSecurityException: Bad user name or password
                                    at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:28)
                                    at org.eclipse.paho.client.mqttv3.internal.ClientState.notifyReceivedAck(ClientState.java:990)
                                    at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:118)
                                    at java.lang.Thread.run(Thread.java:745)
                            

                            I do not need mqtt so does it have to be enabled for mcagent to work? I even allowed annonymous login in mqtt settings and still no rpi-internal appears! ??? - How do I add the internal node? A nice feature would be a 'scan for new nodes' button - not sure how feasible that would be though! 😉

                            J 1 Reply Last reply 5 Jul 2017, 11:49 Reply Quote 0
                            • J Offline
                              jkandasa @skywatch
                              last edited by 5 Jul 2017, 11:49

                              @skywatch Yes, MCagent uses MQTT to communicate with MyController. Hence you can run this on any RPI. Looks like you have not enabled allow anonymous . Kindly recheck once again.

                              I have added a small document to install mcagent on RPI. You can follow the document here

                              N 1 Reply Last reply 19 Jul 2017, 18:40 Reply Quote 0
                              • skywatchS Offline
                                skywatch
                                last edited by skywatch 7 Jun 2017, 14:11 6 Jul 2017, 08:40

                                You asked for suggestions so here's a couple for now....

                                1. Monitor and report network lan traffic bandwidth used (maybe with options to see different types of traffic eg tcp/http/udp etc....).

                                2. Get data for the number of packets sent/received by the nrf24l01+ attached to the pi.

                                Still, it's working well now and very useful to see this info!

                                1 Reply Last reply Reply Quote 1
                                • J Offline
                                  jkandasa @Tag
                                  last edited by 7 Jul 2017, 12:40

                                  @Tag said:

                                  @jkandasa

                                  Thx!,
                                  Will keep an eye open for a new release!

                                  Just in the mean time, how to fill a variable from a file?, i have tried to get this using jscript however i am not a java programmer...

                                  i.e, ont the OrangePI in armbianthe cpu temp is stored here:

                                  /sys/class/thermal/thermal_zone0/temp
                                  and here is the cpu frequency

                                  /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq
                                  Another nice one would be the memory usage:

                                  /sys/fs/cgroup/memory/memory.usage_in_bytes
                                  would it be possible to read these in a script and add them to the database?

                                  Thx!

                                  Hi @Tag
                                  Here is the javascript to read and update RPI-internal values to MyController DB.

                                  var myImports = new JavaImporter(java.io, java.lang, java.util, java.text, org.apache.commons.io.FileUtils);
                                  
                                  with(myImports) {
                                    //get Sensors with UID tag
                                    var temperatureSensor = mcApi.uidTag().getByUid("rpi-temperature").getResource();
                                    var memorySensor = mcApi.uidTag().getByUid("rpi-memory").getResource();
                                    //var cpuFreqSensor = mcApi.uidTag().getByUid("rpi-cpu-freq").getResource();
                                  
                                    var temperature = FileUtils.readFileToString(FileUtils.getFile("/sys/class/thermal/thermal_zone0/temp"));
                                    var memory = FileUtils.readFileToString(FileUtils.getFile("/sys/fs/cgroup/memory/memory.usage_in_bytes"));
                                    //var cpuFrequency = FileUtils.readFileToString(FileUtils.getFile("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq "));
                                  
                                    //Change values
                                    temperatureSensor.value = parseInt(temperature) / 1000;
                                    memorySensor.value = parseInt(memory);
                                    //cpuFreqSensor.value = parseInt(cpuFrequency);
                                  
                                    //Update to db
                                    mcApi.sensor().sendPayload(temperatureSensor);
                                    mcApi.sensor().sendPayload(memorySensor);
                                    //mcApi.sensor().sendPayload(cpuFreqSensor);
                                  }
                                  

                                  I have commented out CPU frequency read. It needs root privilage. If you want cpuFreqSensor to be executed, you need to run MyController as root user. For me cpuFreqSensor is useless value. It never change. It is up to you.

                                  To run this script you have to create dummy node(ex:rpi-internals-dummy) and dummy sensors for temperature, memory and cpuFrequency. And map all these sensors with UID tags to refer to the script.

                                  You can configure this script on timer to update temperature value for N minutes once.

                                  T 1 Reply Last reply 7 Jul 2017, 21:44 Reply Quote 0
                                  • T Offline
                                    Tag MOD @jkandasa
                                    last edited by Tag 7 Aug 2017, 16:34 7 Jul 2017, 21:44

                                    @jkandasa

                                    Got it working for the CPU temp!!
                                    Only problem is the CPU frequency and memory usage, for both i am not able to add a variable type when adding the sensor... this makes it impossible to add a uuid tag since the fake sensors memory and cpu simply do not show up when adding the uuid tag

                                    On the CPU frequency... the H2+ CPU is able to scale the frequency automagically between i.e 240mhz and 1.2Ghz... this saves power and therefore makes the CPU run cooler... my OPI zero is using 500mah max these days (only peeking to 1-1.2Ghz several times per minute)... so for me it interesting to see the cpu frequency, if it is high all the time, i might have a cpu hog somewhere...
                                    No need to run mysensors as root, i will create a root cronjob dumping the value into a file which is readable for the world, and read that file from your script;)

                                    Thanks for helping to get this work, i can imagine this script is very usefull for the MyController community!!!

                                    MyController just got even better!!
                                    (hard to imagine but it seems possible!)

                                    J 1 Reply Last reply 8 Jul 2017, 03:54 Reply Quote 1
                                    • J Offline
                                      jkandasa @Tag
                                      last edited by 8 Jul 2017, 03:54

                                      @Tag said:

                                      Only problem is the CPU frequency and memory usage, for both i am not able to add a variable type when adding the sensor... this makes it impossible to add a uuid tag since the fake sensors memory and cpu simply do not show up when adding the uuid tag

                                      If you use the SNAPSHOT version of MyController you can see CPU/Memory. I hope it will work only for MyController type gateway.

                                      Another way, You can map CPU and Memory with >> Custom type and Variable 1 and Variable 2. Edit both variables and set Metric type as Double. Now all set.

                                      T 1 Reply Last reply 9 Jul 2017, 07:10 Reply Quote 0
                                      • T Offline
                                        Tag MOD @jkandasa
                                        last edited by 9 Jul 2017, 07:10

                                        @jkandasa

                                        Did some testing, got the memory usage setup as you pointed out.
                                        Mapped memory to type custom and variable1. Now it shows the memory usage! (i divided it by 1024 to see the Kb's in use, since that gives me a more usable number)

                                        CPU is still work in progress, will keep you posted!, many thanks for the help!!

                                        1 Reply Last reply Reply Quote 1
                                        • N Offline
                                          naguraob @jkandasa
                                          last edited by 19 Jul 2017, 18:40

                                          @jkandasa
                                          I have followed your instructions to setup the MCAgent, and its up and running.
                                          I need only rpi-internal node hence I commented the following line in mcagent.properties file.
                                          mcac.node.name.gpio=rpi-gpio

                                          But I still see a node being created EUI as rpi-gpio whenever I restart the mcagent.
                                          Can you please help me with this?

                                          In devices.yaml file is it possible for me to change the ids i.e. can id: cpu_temperature be changed to id: CPU_TEMP?

                                          J 1 Reply Last reply 20 Jul 2017, 15:26 Reply Quote 0
                                          • First post
                                            Last post

                                          0

                                          Online

                                          618

                                          Users

                                          531

                                          Topics

                                          3.4k

                                          Posts
                                          Copyright © 2015-2025 MyController.org | Contributors | Localization