MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    1. Home
    2. hikano765
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.
    H
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 2
    • Posts 2
    • Groups 0

    hikano765

    @hikano765

    0
    Reputation
    1
    Profile views
    2
    Posts
    0
    Followers
    0
    Following
    Joined
    Last Online

    hikano765 Unfollow Follow

    Latest posts made by hikano765

    • MM2 can get POST API?

      I am developing a module of MM.
      By the way, I want to control one of these modules by an external client, and I want to do that control method by REST API method.
      For example, if an external client sends a POST API to MM2, the corresponding message is displayed on the MM2 screen.
      I don’t know because I haven’t read the MM2 code in detail, but as far as I’ve checked, the server also automatically turns on when running MM2, so I want to process REST API communication on that server as well, but which file should I modify and put a phrase related to REST API communication in order that?

      server.js?
      server_function.js?

      Examples of API codes that I want to put in are these.
      The API code is an API that stores the message as a txt file when a message is transmitted in a POST method.

      app.post('/api/saveMessage', (req, res) => {
          const message = req.body.message;
      
          if (!message) {
              res.status(400).send('Message not provided.');
              return;
          }
      
          fs.unlink(`appid.txt`, (err) => {
              fs.appendFile(`appid.txt`, message + '\n', (err) => {
                  if (err) {
                      console.error('Error saving message:', err);
                      res.status(500).send('Error saving message');
                  } else {
                      res.send('The message was saved successfully..');
                  }
              });
          });
      });
      
      posted in Development
      H
      hikano765
    • wlan0 IP address in config file

      I want to open the server with the first IP address of the wlan0 network by putting ifaces.wlan0[0].address in the address part of the config.js file. I modified the code to do this, but I get an error on the screen.

      const os = require("os");
      
      const ifaces = os.networkInterfaces();
      const wlan0Address = ifaces.wlan0[0].address;
      
      let config = {
          address: wlan0Address, // The first IP address of the wlan0 network interface
          port: 8080, 
          // etc...
      };
      

      If I write the code as above, I don’t know why, but when I open the server, I don’t see any module screen on the web server. So I thought the modules were a problem, so I modified the code as follows, and the modules come out well from the web server at that address.

      /*const os = require("os");
      const ifaces = os.networkInterfaces();
      const wlan0Address = ifaces.wlan0[0].address;
      */
      let config = {
          address: "xxx.xxx.xxx.xxx", // static address
          port: 8080, 
          // etc...
      };
      

      The conclusion that I came up with through this process is

      const os = require("os");
      const ifaces = os.networkInterfaces();
      const wlan0Address = ifaces.wlan0[0].address;
      

      I think the code in the above part is problematic, I want to know exactly what the problem is with this code, and how to fix the code to solve it.

      In addition, since English is not the main language, I hope you understand that my writing may have some grammatical errors.

      posted in Troubleshooting
      H
      hikano765