Cześć, mam problem z biblioteką Johnny-Five (biblioteka do sterowania mikrokontrolerami np. ardunio z wgranym oprogramowaniem firmata - ja tu akurat używam nodemcu v3) i już trochę mnie krew zalewa .
Używałem jej wielokrotnie, kilka projektów na niej zrobiłem. Nawet mam pliki projektów, które na niej mi działały (nawet z ówczesnym node_modules). Cały kod zamieszczam poniżej, bez skracania - gdyby miałoby coś mi umknąć, gdzie popełniam błąd. Są to 3 przykłady użycia mojej płytki. Jednak coś nie działa na dzień dzisiejszy - uruchomienie jakiegokolwiek skryptu z johnny-five nie pozwala na uruchomienie kodu.
W tej wersji, która działała zwracany jest błąd:
D:\NodeMCU Johnny-Five Test\helloWorld\node_modules\firmata\lib\com.js:61
throw "Missing serialport dependency";
^
Missing serialport dependency
(Use `node --trace-uncaught ...` to show where the exception was thrown)
Po przeinstalowaniu bibliotek błąd się zmienia w:
C:\Users\Amaranthuss\Desktop\helloWorld>node main.ts
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'firmata'
Require stack:
- C:\Users\Amaranthuss\Desktop\helloWorld\node_modules\johnny-five\lib\board.js
- C:\Users\Amaranthuss\Desktop\helloWorld\node_modules\johnny-five\lib\accelerometer.js
- C:\Users\Amaranthuss\Desktop\helloWorld\node_modules\johnny-five\lib\johnny-five.js
- C:\Users\Amaranthuss\Desktop\helloWorld\main.ts
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Board.connect (C:\Users\Amaranthuss\Desktop\helloWorld\node_modules\johnny-five\lib\board.js:107:16)
at new Board (C:\Users\Amaranthuss\Desktop\helloWorld\node_modules\johnny-five\lib\board.js:289:24)
at Object.<anonymous> (C:\Users\Amaranthuss\Desktop\helloWorld\main.ts:5:15)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
at Module.load (node:internal/modules/cjs/loader:981:32) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\Amaranthuss\\Desktop\\helloWorld\\node_modules\\johnny-five\\lib\\board.js',
'C:\\Users\\Amaranthuss\\Desktop\\helloWorld\\node_modules\\johnny-five\\lib\\accelerometer.js',
'C:\\Users\\Amaranthuss\\Desktop\\helloWorld\\node_modules\\johnny-five\\lib\\johnny-five.js',
'C:\\Users\\Amaranthuss\\Desktop\\helloWorld\\main.ts'
]
}
Próbowałem doinstalować samemu firmata, ale nie da się. Dodatkowo patrząc na forum, nie jestem jedynym co miał taki problem, tyle że u mnie nie pomaga instalacja. Cytując z forum "Weird 0_o" problem . Zawartość błędu:
npm ERR! code 1
npm ERR! path C:\Users\Amaranthuss\Desktop\helloWorld\node_modules\@serialport\bindings
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c prebuild-install --tag-prefix @serialport/bindings@ || node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@8.4.1
npm ERR! gyp info using node@16.14.2 | win32 | x64
npm ERR! gyp info find Python using Python version 3.10.4 found at "C:\Python310\python.exe"
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS msvs_version not set from command line or npm config
npm ERR! gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
npm ERR! gyp ERR! find VS checking VS2019 (16.11.32413.511) found at:
npm ERR! gyp ERR! find VS "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools"
npm ERR! gyp ERR! find VS - found "Visual Studio C++ core features"
npm ERR! gyp ERR! find VS - found VC++ toolset: v142
npm ERR! gyp ERR! find VS - missing any Windows SDK
npm ERR! gyp ERR! find VS could not find a version of Visual Studio 2017 or newer to use
npm ERR! gyp ERR! find VS looking for Visual Studio 2015
npm ERR! gyp ERR! find VS - not found
npm ERR! gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS You need to install the latest version of Visual Studio
npm ERR! gyp ERR! find VS including the "Desktop development with C++" workload.
npm ERR! gyp ERR! find VS For more information consult the documentation at:
npm ERR! gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Could not find any Visual Studio installation to use
npm ERR! gyp ERR! stack at VisualStudioFinder.fail (C:\Users\Amaranthuss\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:122:47)
npm ERR! gyp ERR! stack at C:\Users\Amaranthuss\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:75:16
npm ERR! gyp ERR! stack at VisualStudioFinder.findVisualStudio2013 (C:\Users\Amaranthuss\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:363:14)
npm ERR! gyp ERR! stack at C:\Users\Amaranthuss\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:71:14
npm ERR! gyp ERR! stack at C:\Users\Amaranthuss\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:384:16
npm ERR! gyp ERR! stack at C:\Users\Amaranthuss\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\util.js:54:7
npm ERR! gyp ERR! stack at C:\Users\Amaranthuss\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\util.js:33:16
npm ERR! gyp ERR! stack at ChildProcess.exithandler (node:child_process:406:5)
npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:526:28)
npm ERR! gyp ERR! stack at maybeClose (node:internal/child_process:1092:16)
npm ERR! gyp ERR! System Windows_NT 10.0.19044
npm ERR! gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Amaranthuss\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd C:\Users\Amaranthuss\Desktop\helloWorld\node_modules\@serialport\bindings
npm ERR! gyp ERR! node -v v16.14.2
npm ERR! gyp ERR! node-gyp -v v8.4.1
npm ERR! gyp ERR! not ok
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Amaranthuss\AppData\Local\npm-cache\_logs\2022-04-19T20_41_01_223Z-debug-0.log
Poniżej kod 3 wariantów aplikacji, które w pełni działały.
{
"compilerOptions": {
"module": "commonjs"
},
"exclude": [
"node_modules"
]
}
{
"name": "helloworld",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"@types/johnny-five": "^1.3.2",
"etherport-client": "^0.1.4",
"johnny-five": "^2.1.0",
"keypress": "^0.2.1",
"node-pixel": "^0.11.0",
"typescript": "^4.4.3"
},
"devDependencies": {
"ts-node": "^10.2.1"
}
}
const { EtherPortClient } = require("etherport-client")
const { Board, Led } = require("johnny-five")
const keypress = require("keypress")
const board = new Board({
port: new EtherPortClient({
host: "192.168.8.122",
port: 3030,
}),
repl: false,
})
keypress(process.stdin)
const LED_PIN = 2
board.on("ready", () => {
console.log("Board ready")
var led = new Led(LED_PIN)
console.log("Use Up and Down arrows for On and Off. Space to stop.")
process.stdin.resume()
process.stdin.setEncoding("utf8")
process.stdin.setRawMode(true)
process.stdin.on("keypress", (ch, key) => {
if (!key) {
return
}
if (key.name === "q") {
console.log("Quitting")
process.exit()
} else if (key.name === "up") {
console.log("Blink")
led.blink()
} else if (key.name === "down") {
console.log("Stop blinking")
led.stop()
}
})
})
var five = require('johnny-five')
const { EtherPortClient } = require("etherport-client")
const { Board } = require("johnny-five")
const board = new Board({
port: new EtherPortClient({
host: "192.168.8.122",
port: 3030,
}),
repl: false,
})
board.on('ready', function () {
var multi = new five.Multi({
controller: 'HTU21D'
})
multi.on('change', function () {
console.log('Thermometer')
console.log(' celsius : ', this.thermometer.celsius)
console.log(' fahrenheit : ', this.thermometer.fahrenheit)
console.log(' kelvin : ', this.thermometer.kelvin)
console.log('--------------------------------------')
console.log('Hygrometer')
console.log(' relative humidity : ', this.hygrometer.relativeHumidity)
console.log('--------------------------------------')
})
})
const { EtherPortClient } = require("etherport-client")
const { Board } = require("johnny-five")
const board = new Board({
port: new EtherPortClient({
host: "192.168.8.122",
port: 3030,
}),
repl: false,
})
board.on('ready', function () {
board.pinMode(16, 3)
board.analogWrite(16, 1024)
let state = false
setInterval(() => {
const out = state === true ? 255 : 75
board.analogWrite(16, out)
console.log(state, out)
state = !state
}, 10000)
})
Skończyły mi się pomysły, a pilnie tego potrzebuję, bo chciałem zamówić większość ilość płytek i oprogramować pod własny prosty smartdom.
Czy ma ktoś może pomysł, co się wysypało? Próbowałem na drugim komputerze od zera, identyczna sytuacja. Samo new Board już wysypuje skrypt. Zamieszczam dwa przykłady z poradników (pierwszy, drugi), z których korzystałem z robiąc powyższe przykłady.
Bez płytki powinien z tego co wiem uruchomić się program i po prostu zgłosić, że nie może się połączyć z płytką pod wskazanym IP.
Z góry dziękuję za pomoc.