Knowledge Base
HOME » KNOWLEDGE BASE » FORUM

Module 5 (Building a Custom Integration): Error installing TTN SDK

Hello everyone,

After finally resolving my connectivity issues, I've moved on to creating a custom integration. However, I'm stuck trying to install the TTN SDK via the Node.js command line. The instructions for the portion I'm stuck on are below.

"Start listening to events
To listen to events on The Things Network, we will use The Things Network application SDK.

First, install the SDK using npm:

$ npm install --save ttn
This will download ttn and add it (thanks to the --save option) to the list of dependencies of your project in package.json."

Essentially, I'm getting several errors when I try to install the TTN SDK, and I'm not sure how to interpret or resolve the errors that I'm receiving. These errors are indicated below:

C:\Users\MyName\server\server.js:1
server.jsconsole.log("Starting server...")
^

ReferenceError: server is not defined
at Object. (C:\Users\MyName\server\server.js:1:1)
[90m at Module._compile (internal/modules/cjs/loader.js:776:30)[39m
[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)[39m
[90m at Module.load (internal/modules/cjs/loader.js:643:32)[39m
[90m at Function.Module._load (internal/modules/cjs/loader.js:556:12)[39m
[90m at Function.Module.runMain (internal/modules/cjs/loader.js:839:10)[39m
[90m at internal/main/run_main_module.js:17:11[39m

C:\Users\MyName\server>npm install --save ttn
npm ERR! path git
npm ERR! code ENOENT
npm ERR! errno ENOENT
npm ERR! syscall spawn git
npm ERR! enoent Error while executing:
npm ERR! enoent undefined ls-remote -h -t https://github.com/thethingsnetwork/api.git
npm ERR! enoent
npm ERR! enoent
npm ERR! enoent spawn git ENOENT
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:

Any help would be greatly appreciated!!!
Avatar
Hi,

First issue: There is a "new line" display issue with our new website for all code blocks.
You should put the following code in the file "server.js"
```
// server.js
console.log("Starting server...")
```
So running "node server.js" will now work and return "Starting server..."


Second issue: It seems that git is not installed or not in the path. What is your operating system ? See git documentation: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git

Hi Olivier,

Thank you for your help. I was able to get past this step, but seem to be having issues with the 'sending downlink' portion of this module.

https://lora-developers.semtech.com/resources/lorawan-academy/courses/sending-downlink-2/

I followed all of the steps--I can view data in my web browser, I've added LED on/off buttons, but I can't seem to actually send a downlink. I checked the TTN console and confirmed that downlinks are not being scheduled but I cannot figure out why. I've attached both the server and client files (with device/app info removed), do you see anything that might be preventing the downlink from being scheduled?
File Attachments
server_file.txt  (File Size: 2KB - Downloads: 18)
won't let me attach the client file so pasting below:

// public/client.js

const ws = new WebSocket("ws://" + [removed].host + "/data")

ws.addEventListener("open", function () {
console.log("Socket opened!")
})

ws.addEventListener("error", function (error) {
console.log("Socket errored:", error)
})

ws.addEventListener("message", function (message) {
// parse incoming messages as JSON and add them to the list of events.
var payload = JSON.parse(message.data)
addEvent(payload)
})

// addEvent adds the event to the list of events.
function addEvent (event) {
// search for the html element with the id="events" in our index.html page
var list = document.getElementById("events")
// create an li element to add to our list (declared with ul)
var li = document.createElement("li")
li[removed] = "
" + JSON.stringify(event, null, 2) + "
"
// add the element to the list
list.prepend(li)
}


}
// setLED instructs the backend to send a downlink message with the led field set to status.
function setLED (status) {
const payload = {
type: "downlink",
fields: {
state: {
led: status,
},
},
}
ws.send(JSON.stringify(payload))
alert("Downlink scheduled!")
}
// select element with the id="downlink-on" in our case the LED on button and call the setLED() function with true.
document.getElementById("downlink-on").addEventListener("click", function () {
setLED(true)
})
// select element with the id="downlink-off" in our case the LED off button and call the setLED() function with false.
document.getElementById("downlink-off").addEventListener("click", function () {
setLED(false)
})
‹‹ Lora and health      Course Prerequisites ››