Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TCORE-250 Refactor and Test Raspberry PI Plugin for Monorepo #71

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 132 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
26 changes: 26 additions & 0 deletions plugins/rabbitmq/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@tago-io/tcore-plugin-rabbitmq",
"version": "0.7.0",
"private": false,
"main": "./src/index.ts",
"type": "module",
"tcore": {
"name": "RabbitMQ",
"short_description": "Integrates the RabbitMQ queue with TagoCore",
"full_description": "./README.md",
"icon": "./assets/icon.png",
"types": ["queue"],
"permissions": ["device-data"],
"publisher": {
"name": "TagoIO",
"domain": "tago.io"
}
},
"dependencies": {
"amqplib": "0.10.4",
"knex": "3.1.0"
},
"devDependencies": {
"@types/amqplib": "0.10.5"
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
import { IPluginConfigField } from "@tago-io/tcore-sdk/build/Types";
import type { IPluginConfigField } from "@tago-io/tcore-sdk/Types";

const configs: IPluginConfigField[] = [
{ type: "string", name: "Host", field: "host", defaultValue: "localhost", icon: "hdd", required: true },
{ type: "number", name: "Port", field: "port", defaultValue: 5672, icon: "network-wired", required: true },
{ type: "string", name: "Queue name", field: "queue", defaultValue: "tcore-data", icon: "envelope", required: true },
{
type: "string",
name: "Host",
field: "host",
defaultValue: "localhost",
icon: "hdd",
required: true,
},
{
type: "number",
name: "Port",
field: "port",
defaultValue: 5672,
icon: "network-wired",
required: true,
},
{
type: "string",
name: "Queue name",
field: "queue",
defaultValue: "tcore-data",
icon: "envelope",
required: true,
},
{
type: "string",
name: "User",
defaultValue: "root",
placeholder: "root",
tooltip: "User name to use for the connection",
icon: "user-alt",
field: `user`,
field: "user",
required: true,
},
{
Expand All @@ -20,14 +41,14 @@ const configs: IPluginConfigField[] = [
placeholder: "root",
tooltip: "Optional password for the account used",
icon: "key",
field: `password`,
field: "password",
},
{
type: "number",
name: "Batch size (per node)",
icon: "bucket",
tooltip: "Max processing messages per node (cluster mode)",
field: `prefetch`,
field: "prefetch",
min: 0,
max: 65535,
},
Expand All @@ -36,7 +57,7 @@ const configs: IPluginConfigField[] = [
name: "Message time to live (ms)",
icon: "clock",
tooltip: "Lifetime of message in ms",
field: `msg_ttl`,
field: "msg_ttl",
min: 0,
},
];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { QueueModule } from "@tago-io/tcore-sdk";
import { IDatabaseDeviceDataCreate } from "@tago-io/tcore-sdk/build/Types";
import amqplib, { Channel } from "amqplib";
import { consumeData } from "./consume-data";
import { Config } from "./types";
import type { QueueModule } from "@tago-io/tcore-sdk";
import type { IDatabaseDeviceDataCreate } from "@tago-io/tcore-sdk/Types";
import amqplib, { type Channel } from "amqplib";
import { consumeData } from "./consume-data.ts";
import type { Config } from "./types.ts";

let consumer: Channel;
let sender: Channel;
Expand All @@ -21,7 +21,7 @@ async function createConnection(this: QueueModule, config: Config) {

queue = config.queue;

if (config.msg_ttl != undefined) {
if (config.msg_ttl !== undefined) {
ttl = config.msg_ttl;
}

Expand Down Expand Up @@ -61,4 +61,11 @@ async function addToQueue(deviceID: string, data: IDatabaseDeviceDataCreate[]) {
});
}

export { consumer, sender, info, createConnection, closeConnection, addToQueue };
export {
consumer,
sender,
info,
createConnection,
closeConnection,
addToQueue,
};
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { core } from "@tago-io/tcore-sdk";
import { ConsumeMessage } from "amqplib";
import { consumer } from "./connection";
import type { ConsumeMessage } from "amqplib";
import { consumer } from "./connection.ts";

function consumeData(msg: ConsumeMessage | null): void {
if (msg === null) {
return console.error("Consumer cancelled by server");
console.error("Consumer cancelled by server");
return;
}

const data = JSON.parse(msg.content.toString());
Expand All @@ -16,7 +17,9 @@ function consumeData(msg: ConsumeMessage | null): void {
consumer.ack(msg);
})
.catch((e) => {
console.error(`ERROR: ${JSON.stringify({ deviceID, data, error: e?.message | e })}`);
console.error(
`ERROR: ${JSON.stringify({ deviceID, data, error: e?.message | e })}`,
);

return consumer.reject(msg, false);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { QueueModule } from "@tago-io/tcore-sdk";
import { configs } from "./configurations";
import { addToQueue, closeConnection, createConnection } from "./connection";
import { configs } from "./configurations.ts";
import { addToQueue, closeConnection, createConnection } from "./connection.ts";

const rabbitMQ = new QueueModule({
id: "rabbit-mq",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ type Config = {
msg_ttl?: number;
};

export { Config };
export type { Config };
19 changes: 19 additions & 0 deletions plugins/raspberry-pi-gpio/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@tago-io/tcore-plugin-raspberry-pi-gpio",
"version": "0.5.0",
"private": false,
"main": "./src/index.ts",
"type": "module",
"tcore": {
"name": "Raspberry Pi",
"short_description": "Read and Activate GPIO Pins of Raspberry Pi",
"full_description": "./README.md",
"icon": "./assets/icon.png",
"types": ["action-type", "action-trigger", "service"],
"permissions": ["device", "device-data"]
},
"dependencies": {
"rpio": "2.4.2"
},
"devDependencies": {}
}
Loading
Loading