Skip to content

Commit

Permalink
Merge pull request #26 from linto-ai/merge-linto-agent
Browse files Browse the repository at this point in the history
Merge linto agent
  • Loading branch information
Houpert authored Jan 19, 2024
2 parents a9efe1a + 1d9c4a8 commit 6f9a5a0
Show file tree
Hide file tree
Showing 528 changed files with 44,876 additions and 1 deletion.
68 changes: 67 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,67 @@
devcerts/*.pem
build/
stack/devcerts/*.pem

.vscode
**/dev-build
**/.cache
lib/terminal/linto.json

# Env
.env

# node Version
.nvmrc

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz
tmp/

# Other
.history/
temp/

**/.env
**/node_modules

**/settings.tmp.js
**/json_tmp
**/public/tockapp.json
**/public/tocksentences.json
**/dist
**/.local_cmd
**/data
**/dump.rdb
/webserver/model/mongodb/schemas

**/model/*
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# LinTO-Agent

## Platform
LinTO-Agent contain all tools allowing to play with LinTO
- linto-admin : central manager for a given fleet of LinTO clients
- business-logic-server : deploy and executes a linto workflow
- overwatch : handle the authentification and loging aspect of a linto fleet
- service-broker : the communication pipeline between services and subservices
- stt-service-manager : deploy speech to text service

## Setup

LinTO Agent is meant to get deployed on a Docker Swarm cluster. Please read thouroughly the [infrastructure setup guide](https://doc.linto.ai/) and the following documentation located on `stack/docs/README.md` BEFORE you run the startup script.
11 changes: 11 additions & 0 deletions client/rpi/.envdefault
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Components loading in this order, components are orchestration plugins for the LinTO client actions
COMPONENTS = localmqtt,logicmqtt,audio

# Local MQTT bus setup
LOCAL_MQTT_ADDRESS = 127.0.0.1
LOCAL_MQTT_PORT = 1883
LOCAL_MQTT_KEEP_ALIVE = 15

# Audio and Mic
AUDIO_FILE = /tmp/command.raw
TTS_LANG = fr-FR,en-US,en-GB,es-ES,de-DE,it-IT
4 changes: 4 additions & 0 deletions client/rpi/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.vscode/
node_modules
.env
lib/terminal/linto.json
31 changes: 31 additions & 0 deletions client/rpi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# LinTO client

LinTO Client-server connectivity

This module sequences actions, dispatches informations or triggers between any other modules on the LinTO device
This module is part of the LinTO project, it's the only remote subscriber/publisher, through MQTT(s) protocol, to the LinTO business-logic and exploitation servers.

## Dependencies

This program uses a **node.js 9+** runtime. before first run you first need to install node module dependencies

```
npm install
```

## HOW TO Use the module

create a .env file based on .envdefault
run the software with :
```
node index.js
```
You might overload any of environement variables at runtime
```
node MY_PREFERED_VALUE=42 index.js
```

You shall use something like **PM2** to maintain the process.


**Have fun building your LinTO**
21 changes: 21 additions & 0 deletions client/rpi/components/audio/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const moduleName = 'audio'
const debug = require('debug')(`linto-client:${moduleName}`)
const EventEmitter = require('eventemitter3')

class Audio extends EventEmitter {
constructor(app) {
super()
this.nlpProcessing = new Array() //array of audiofiles being submitted
this.mic = require(`${process.cwd()}/lib/soundfetch`)
return this.init(app)
}

async init(app) {
return new Promise((resolve, reject) => {
app[moduleName] = this
resolve(app)
})
}
}

module.exports = Audio
106 changes: 106 additions & 0 deletions client/rpi/components/localmqtt/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
const moduleName = 'localmqtt'
const debug = require('debug')(`linto-client:${moduleName}`)
const EventEmitter = require('eventemitter3')
const Mqtt = require('mqtt')

class LocalMqtt extends EventEmitter {
constructor(app) {
super()
this.subTopics = [
"wuw/wuw-spotted",
"utterance/stop"
]
this.cnxParam = {
clean: true,
servers: [{
host: process.env.LOCAL_MQTT_ADDRESS,
port: process.env.LOCAL_MQTT_PORT
}],
keepalive: parseInt(process.env.LOCAL_MQTT_KEEP_ALIVE), //can live for LOCAL_MQTT_KEEP_ALIVE seconds without a single message sent on broker
reconnectPeriod: Math.floor(Math.random() * 1000) + 1000, // ms for reconnect,
will: {
topic: `lintoclient/status`,
retain: true,
payload: JSON.stringify({
connexion: "offline"
})
},
qos: 2
}
this.on(`localmqtt::connect`, () => {
console.log(`${new Date().toJSON()} Local MQTT connexion up`)
this.publish('status', { //send retained online status
"connexion": "online",
"on": new Date().toJSON()
}, 0, true, true)
})
return this.init(app)
}

async init(app) {
return new Promise((resolve, reject) => {
this.client = Mqtt.connect(this.cnxParam)
this.client.on("error", e => {
console.error(`${new Date().toJSON()} Local MQTT broker error ${e}`)
})
this.client.on("connect", () => {
this.emit(`${moduleName}::connect`)
//clear any previous subsciptions
this.subTopics.map((topic) => {
this.client.unsubscribe(topic, (err) => {
if (err) debug('disconnecting while unsubscribing', err)
//Subscribe to the client topics
debug(`subscribing topics...`)
this.client.subscribe(topic, (err) => {
if (!err) {
debug(`subscribed successfully to ${topic}`)
} else {
debug(err)
}
})
})
})
})

this.client.on("offline", () => {
console.error(`${new Date().toJSON()} Local MQTT connexion down`)
})

this.client.on('message', (topic, payload) => {
debug(topic, payload)
try {
let subTopics = topic.split("/")
payload = JSON.parse(payload.toString())
let command = subTopics.pop()
let topicRoot = subTopics.pop()
this.emit(`${moduleName}::${topicRoot}/${command}`, payload)
} catch (err) {
debug(err)
}
})
app[moduleName] = this
resolve(app)
})
}

publish(topic, value, qos = 2, retain = false, requireOnline = false) {
const pubTopic = 'lintoclient' + '/' + topic
const pubOptions = {
"qos": qos,
"retain": retain
}
if (requireOnline === true) {
if (this.client.connected === true) {
this.client.publish(pubTopic, JSON.stringify(value), pubOptions, function (err) {
if (err) debug("publish error", err)
})
}
} else {
this.client.publish(pubTopic, JSON.stringify(value), pubOptions, function (err) {
if (err) debug("publish error", err)
})
}
}
}

module.exports = LocalMqtt
Loading

0 comments on commit 6f9a5a0

Please sign in to comment.