MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    MagicMirror and adruino over ethernet

    Scheduled Pinned Locked Moved General Discussion
    26 Posts 3 Posters 10.2k 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.
    • K Offline
      Kereknjek
      last edited by

      I think that this is way to extensive for my knowledge. I can’t make heads or tails out of it…

      S 1 Reply Last reply Reply Quote 0
      • S Offline
        sdetweil @Kereknjek
        last edited by

        @Kereknjek basically the arduino sends text strings with Serial.println(“[COMMAND:NAME:DATA]”)

        To transmit a sensor data to the module: `[sensor:SENSOR_NAME:SENSOR_VALUE]**

        Example:

        Serial.println(“[sensor:MQ2:19]”);
        Serial.println(“[sensor:LM35:11]”);
        Serial.println(“[sensor:HCSR04:64]”);

        but anyhow, lots of work in the arduino code to make this work

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        K 1 Reply Last reply Reply Quote 0
        • K Offline
          Kereknjek @sdetweil
          last edited by Kereknjek

          @sdetweil
          That part is perfectly clear.

          Here is C/P of what I am using now:

                client.println("< !DOCTYPE HTML >");
                client.println("< html >");
                client.print("Napon panela: ");
                client.print(PanelU);
                client.println(" V < br/>");
                client.print("Struja panela: ");
                client.print(PanelI);
                client.println(" A < br/>");
                client.print("Napon baterije: ");
                client.print(BatU);
                client.println(" V < br/>");
          

          .
          .
          .
          client.println(“< / html >”);

          That is slightly modified ethernet server sample program from ethernet library.

          Edit: had to add spaces because html wasn’t showing.

          S 1 Reply Last reply Reply Quote 0
          • B Offline
            BD0G
            last edited by

            This may be a stupid question , but . Why not just use the MMM-iFrame Module since the information is already provided /served from a webserver within the Arduino? You can change the size of the iFrame that displays the Url so that it can be small and take up just a little of the magic mirror or large and fill the mirror. Since you will not be touching the screen to change or interact with the data.

            1 Reply Last reply Reply Quote 0
            • K Offline
              Kereknjek
              last edited by Kereknjek

              It’s not stupid question.

              If arduino serves webpage, it should be served from sd card.
              To use sd card, you have to use sd card library, make decisions wether client wants whole web page or just data packets…
              All that takes a lot of memory and time to process. And arduino is slow and low on memory compared to RPi.
              For arduino is much simpler to detect “give me data” and send sensor ID and value.

              Plus, in my case, arduino mega has 16 amperemeters to read and 18 outputs to regulate.
              I wouldn’t like it if it gets stuck in code while inverter is working at full capacity. It could become fire hazard.

              B 1 Reply Last reply Reply Quote 0
              • B Offline
                BD0G @Kereknjek
                last edited by

                @Kereknjek So in a nutshell. Yes the Arduino can serve a whole webpage of data , but it will take a long time. If one just sends the data from the Arduino to the Raspberry Pi then the Raspberry Pi can display the webpage faster as its processor and potentially memory is faster.

                1 Reply Last reply Reply Quote 0
                • K Offline
                  Kereknjek
                  last edited by

                  Yes. Plus, if I would want to make any modifications to webpage, first I would have to shutdown arduino and whole solar system, pull sd card out, modify page, plug sd card back in and restart sytem.

                  If sd card gets damaged in any way or get slow for some reason (had one like that on my 3D printer), whole system running on that arduino gets slow and unuseable.

                  B 1 Reply Last reply Reply Quote 0
                  • S Offline
                    sdetweil @Kereknjek
                    last edited by

                    @Kereknjek cool. You could make a little change and have it return just data.

                    If the path is sensor1, send just sensor1’s data. Etc.

                    Pretty easy, just a case stmt… you could make it json data pretty easy too…

                    The request could ask for a sensor or block of sensors, and send raw data.

                    Sam

                    How to add modules

                    learning how to use browser developers window for css changes

                    K 1 Reply Last reply Reply Quote 0
                    • S Offline
                      sdetweil
                      last edited by sdetweil

                      On my Arduino measuring water flow and water volume. I did those in interrupt and timer routines. And sent data in the main path.

                      Sam

                      How to add modules

                      learning how to use browser developers window for css changes

                      1 Reply Last reply Reply Quote 0
                      • B Offline
                        BD0G @Kereknjek
                        last edited by BD0G

                        @Kereknjek Sounds like you need to backup the entire SD Card of your Arduino and create an image for safe keeping. If you Download Win32 Disk Imager you can create an image of the entire SD card and write it to a hard drive. Then if catastrophe strikes simply remove the SD card and use Win 32 Disk Imager to write the working image back to the SD card.

                        It can be downloaded here Win32DiskImager

                        S 1 Reply Last reply Reply Quote 0
                        • S Offline
                          sdetweil @BD0G
                          last edited by

                          @BD0G my 8266 has onboard flash ram. No SD card required.

                          Sam

                          How to add modules

                          learning how to use browser developers window for css changes

                          B 1 Reply Last reply Reply Quote 0
                          • B Offline
                            BD0G @sdetweil
                            last edited by

                            @sdetweil Was referring to @Kereknjek and recommending he backup the SD card on the Arduino that is working for safe keeping.

                            I have an 8266 as well ! Its dedicated to my smartblinds control that I control via smarthings and a custom 3 D printed enclosure for a servo that mounts in the top rail of the blinds. Works splendidly!

                            S 1 Reply Last reply Reply Quote 0
                            • S Offline
                              sdetweil @BD0G
                              last edited by

                              @BD0G I agree, backup is an important strategy. I found out the other day SD cards have a limited life, determined by number of writes…

                              Sam

                              How to add modules

                              learning how to use browser developers window for css changes

                              1 Reply Last reply Reply Quote 0
                              • K Offline
                                Kereknjek @sdetweil
                                last edited by

                                @sdetweil said in MagicMirror and adruino over ethernet:

                                @Kereknjek cool. You could make a little change and have it return just data.

                                If the path is sensor1, send just sensor1’s data. Etc.

                                Pretty easy, just a case stmt… you could make it json data pretty easy too…

                                The request could ask for a sensor or block of sensors, and send raw data.

                                Yes! That is what i’m looking for.
                                But discussion went to arduino side.
                                My problem is that I don’t know how to do it at magic mirror side.

                                S 2 Replies Last reply Reply Quote 0
                                • S Offline
                                  sdetweil @Kereknjek
                                  last edited by

                                  @Kereknjek ok. More later. Grandson on site!

                                  Sam

                                  How to add modules

                                  learning how to use browser developers window for css changes

                                  1 Reply Last reply Reply Quote 0
                                  • S Offline
                                    sdetweil @Kereknjek
                                    last edited by sdetweil

                                    @Kereknjek so. the methods to get data from server (web site http://something) is request()

                                    there are different forms XMLRequest, request… XMLRequest is builtin to the browser that MM runs on (either Electron, or Chrome)

                                    the design of the MM module is in two parts… the part that runs in the browser, and renders the data
                                    this javascript file name matches the module name.

                                    module = someModule, folder = someModule, filename = someModule.js
                                    the ‘module’. js cannot use ‘require’() to load additional scripts… but SOME can be loaded
                                    thru the mm callback at function getScripts()
                                    for builtins, you can just use them

                                    the processing model, is get your data, then call this.updateDom(somedelaytime), to tell MM that new data for your module is ready. the MM runtime will call you modules getDom() function to allow you to construct the html object tree of content to inject into the single page DOM, in the position[modulename] div…
                                    you can see this tree in the developers windows (ctrl-shift-i, select the elements tab)

                                    in some cases the requirements of the data collection require services that are NOT builtin to the browser, serial port, database, complex api calls, etc… so, the MM design provides for a helper for the module, filename called node_helper.js

                                    it can use require() to load service libraries to access outside datasources, or manipulate data.

                                    the module and helper talk to each other thru one api, sendSocketNotification(item_id, data)
                                    and receiveSocketNotification(item_id, data).
                                    the format of item_id is a string, and data can be any format/ totally up to you how you want to use it.

                                    the info provided in the config.js entry for a module, replaces same named items in the module ‘default{}’ object… BUT this data does NOT get sent to the helper UNLESS YOU DO IT.
                                    a convention, is that the module receives notices from the system via notificationReceived (notice no ‘socket’ in the name)… and when the moduel receives the ‘all_modules_started’ notice, the module sends a pointer to the config block to the helper… so they both have the same copy.

                                    my Sample Module has all the parts, in a working example… but doesn’t do much… send the config down,
                                    waits some time, and sends a configured message back up to the module, and then calls this.updated() to indicate new data is available.

                                    you can use request() in the helper, or XMLRequest() in the module (builtin) XMLRequest will process XML or a string. request() cab be any data format (including binary)…

                                    these calls do EXACTLY the same thing as what your browser does when you put in http://some_ip_address to get the web page from your arduino

                                    Sam

                                    How to add modules

                                    learning how to use browser developers window for css changes

                                    K 1 Reply Last reply Reply Quote 0
                                    • K Offline
                                      Kereknjek @sdetweil
                                      last edited by

                                      @sdetweil
                                      Thank you!
                                      Ill need some time to try it out.

                                      Mechanical or should I say, woodwork is finished. I’m still waiting for short hdmi cable, PIR sensor and hinges I ordered… It looks sexy alredy! Can’t wait to see it working.

                                      S 1 Reply Last reply Reply Quote 0
                                      • S Offline
                                        sdetweil @Kereknjek
                                        last edited by

                                        @Kereknjek i would start slow…

                                        use my sample, send one request, get back content. you cannot put a whole page up unless u open an iframe…

                                        MM is called a Single Page Application… (SPA)…
                                        in this model, each ‘module’ contributes a little content (a div’s worth) and that little bit is injected into the running view of the web page (dom=document object model) again, you can see this layout on the developers window, elements tab

                                        u can do this on your Windows PC too with chrome, press ctrl-shift-i on any page (again to turn it off)

                                        Sam

                                        How to add modules

                                        learning how to use browser developers window for css changes

                                        1 Reply Last reply Reply Quote 0

                                        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                        With your input, this post could be even better 💗

                                        Register Login
                                        • 1
                                        • 2
                                        • 2 / 2
                                        • First post
                                          Last post
                                        Enjoying MagicMirror? Please consider a donation!
                                        MagicMirror created by Michael Teeuw.
                                        Forum managed by Sam, technical setup by Karsten.
                                        This forum is using NodeBB as its core | Contributors
                                        Contact | Privacy Policy