require() NPM in Espruino WiFi for HomeKit project

Posted on
  • I am currently working on a HomeKit project with Espruino WiFi and I'm running some tests first.

    There is a git that has a great example (https://github.com/homebridge/HAP-NodeJS­-examples/tree/master/light-example-java­script). The project has a "light.js" program and "package.json". In the terminal (linux), I just install the necessary dependencies with "npm install" and I execute the application "node src/light.js". It works perfectly, I find the extension in Apple HomeKit App in my phone, I can edit the light parameters, everything.

    However, when I try to do the same inside the Espruino Web IDE, I can not access to the module in require("hap-nodejs"). In the terminal, the npm does everything for me, but here I know I need to introduce the .js file in the module section in Espruino Web IDE, but "hap-nodejs" is not a .js file. I need to transform the "package.json" into my "hap-nodejs.js" so I can use it as a private module. I tried to find a way to do it but nothing seems to work. I also downloaded the .tgz file from "https://www.npmjs.com/package/hap-nodejs­", and try to find what I need from there. But it is the same in the end, another package and directories containing the dependencies needed.

    My question is: How can I get the module I need (hap-nodejs) to execute "light.js" inside the Espruino?

    Thanks

  • Hi

    Espruino has a page that describes how to handle modules.

  • Hi MaBe,

    I already checked the page you linked before, however it is not helping me. As I said, I can not convert the package to an actual file .js that I can upload to the Espruino.

    Thanks again

  • Hi - I think the issue you've got is it's a multi-file typescript library. You may have some luck installing it and then using just the dist/index.js file (which is the compiled JS bundle), but looking at it, it pulls in a bunch of extra modules from elsewhere as well - some of which look pretty heavyweight.

    I'm afraid there's a very good chance that there's just too much code to fit on an Espruino device. I'm sure you could make an Espruino device into a HomeKit device, but you may have to implement it from scratch I'm afraid (at least hap-nodejs's dependencies look a bit heavy to me)

  • Hi Gordon,

    I was afraid that would be the case. I tried what you said about "index.js" but it didn't work in the end. I will have to do it from scratch as you suggest. Thanks a lot for the help anyways.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

require() NPM in Espruino WiFi for HomeKit project

Posted by Avatar for M.Montore @M.Montore

Actions