• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
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.

Show calendar based on IP Address accessed

Scheduled Pinned Locked Moved Development
68 Posts 3 Posters 6.3k Views
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.
  • S
    Spinster
    last edited by May 6, 2024, 7:56 AM

    Hi,

    I am trying to provide different calendar for each client based on the IP address they access from. Please advise me where to edit the stock calendar module. I am thinking of adding accessIP under each calendar entry in the config file to enable this.

    Any help will be useful

    S 1 Reply Last reply May 6, 2024, 11:32 AM Reply Quote 0
    • S
      sdetweil @Spinster
      last edited by May 6, 2024, 11:32 AM

      @Spinster so, you would have to change calendar.js and only send requests to get calendar data for the matching calendar configs here, at the call to addCalendar

      1000025883.jpg

      the code already checks to see if the data was for this instance

      Sam

      How to add modules

      learning how to use css

      S 1 Reply Last reply May 6, 2024, 12:10 PM Reply Quote 0
      • S
        Spinster @sdetweil
        last edited by May 6, 2024, 12:10 PM

        Hi @sdetweil ,

        Thank you for your hint, can you please suggest how to get the client’s IP within this function call?
        Also, I tried adding some log message before the add calendar call, I could not see it in the log, am I doing something wrong? Please correct me.

        S 2 Replies Last reply May 6, 2024, 12:37 PM Reply Quote 0
        • S
          sdetweil @Spinster
          last edited by May 6, 2024, 12:37 PM

          @Spinster this component of the module runs in the browser, so you would have to open the developers window, ctrl-shift-i, and select the console tab

          you can also install a module that sends those to the console log. mmm-logging for example.

          for the ip address you will need to create a couple things, as you can only get this from a server side http request

          u need a socketnotification to the node helper to get the server ip address
          then you create an express api service at the server to call and get the client ip address from the request info

          the socketnotification in the node helper doesn’t have that info

          Sam

          How to add modules

          learning how to use css

          S 1 Reply Last reply May 6, 2024, 5:12 PM Reply Quote 0
          • S
            sdetweil @Spinster
            last edited by sdetweil May 6, 2024, 1:17 PM May 6, 2024, 12:49 PM

            @Spinster you could sidestep the 1st part by examining the url of this page in calendar.js to get the server it was loaded from
            https://ui.dev/get-current-url-javascript

            you can use the developers window sources tab to debug that code

            Sam

            How to add modules

            learning how to use css

            S 1 Reply Last reply May 6, 2024, 1:33 PM Reply Quote 0
            • S
              sdetweil @sdetweil
              last edited by May 6, 2024, 1:33 PM

              @Spinster you could add this service as a separate module, with no content to show

              or have a hidden div w the ip address and be able to synchronous search the dom for it

              document.getElementsbyId()… maybe

              Sam

              How to add modules

              learning how to use css

              M 1 Reply Last reply May 6, 2024, 2:22 PM Reply Quote 0
              • M
                MMRIZE @sdetweil
                last edited by MMRIZE May 6, 2024, 2:32 PM May 6, 2024, 2:22 PM

                @Spinster
                Depending on the environment and which modules you want to display on the screen, it may vary, but… If you don’t have many clients (less than 10) and your server has sufficient capacity, it might be better to provide each client with a dedicated server instance with a different port number. For example, Client 1 - Port 8081, Client 2 - Port 8082, … If there are 10 clients, run 10 MM servers.
                You just need to setup config.js of each client-server pair for your purpose.

                There’s no need to modify the source code, and you also don’t need to allocate fixed IP addresses for each client through router settings or WLAN settings of clients. Usually, in home or office environments, DHCP is common, so this would be a simpler approach.

                S 1 Reply Last reply May 6, 2024, 5:14 PM Reply Quote 0
                • S
                  Spinster @sdetweil
                  last edited by May 6, 2024, 5:12 PM

                  @sdetweil I understand about the log. Thank you.

                  Regarding the IP address, I am very new to javascript hence trying to get my head around it. Being a C programmer, certain things in JavaScript is still a distant for me. Hope to understand soon.

                  Just in case if you have some time, a simple code from you would help me. Please.

                  1 Reply Last reply Reply Quote 0
                  • S
                    Spinster @MMRIZE
                    last edited by May 6, 2024, 5:14 PM

                    @MMRIZE I understand, Ideally I would like to avoid opening multiple ports and use a common config to serve clients based on their IP. In fact, though DHCP is used by my home server, I have only assigned the IP address to reservations, hence static IP within my home network is not a problem.

                    Please suggest a simple code to use a specific calendar based on IP address of the client.

                    M 2 Replies Last reply May 6, 2024, 5:58 PM Reply Quote 0
                    • M
                      MMRIZE @Spinster
                      last edited by May 6, 2024, 5:58 PM

                      @Spinster
                      I’m out of my test PC, so I can’t show atm. (Maybe tomorrow possible, if you couldn’t success until that time)
                      You can add custom config attribute map-like object calendarMap in your config.js

                      module: "calendar",
                      position: "top_left",
                      config: {
                        calendarMap: {
                          "192.168.178.100": ["calendar1", "calendar2"],
                          "192.168.178.101": ["calebdar1", "calendar3"],
                        },
                        calendars: [
                          {
                            url: " … ",
                            name: "calendar1",
                          },
                      …
                      
                      

                      In calendar.js around line 176, when CALENDAR_EVENTS notification coming, you can filter the payload(array of events) of that notification by checking calendarName of each event is matched to this.config.calendarMap.

                      Sorry I can’t show the real code now. Maybe some hours later I may be able to. Anyway concept would be like this.

                      S 1 Reply Last reply May 6, 2024, 6:03 PM Reply Quote 0
                      • 1
                      • 2
                      • 3
                      • 4
                      • 5
                      • 6
                      • 7
                      • 2 / 7
                      2 / 7
                      • First post
                        5/68
                        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
                        This website uses cookies to ensure you get the best experience on our website. Learn More