TypeScript API for Awtrix LED Matrix Display
npm install awtrix-tsTS wrapper for Awtrix API.
The Awtrix class provides a TypeScript interface for interacting with the Awtrix device API. It supports device control, settings management, notifications, app switching, indicators, moodlight, and more.
``bash`
npm i --save awtrix-ts
`typescript
import { Awtrix } from 'awtrix-ts';
const awtrix = new Awtrix(new URL('http://your-awtrix-device-ip'));
await awtrix.power(true); // Turn device on
await awtrix.notify({ text: 'Hello World!' }); // Send a notification
`
#### power(power: boolean)
Turn the device on or off.
`typescript`
await awtrix.power(true); // Turn on
await awtrix.power(false); // Turn off
#### reboot()
Reboot the device.
`typescript`
await awtrix.reboot();
#### sleep(time: number)
Put the device to sleep for a specified time (in seconds).
`typescript`
await awtrix.sleep(5); // Sleep for 5 seconds
#### settings(settings: Settings)
Update device settings.
`typescript`
await awtrix.settings({
automaticAppSwitching: false,
globalTextColor: [0, 255, 0],
// ...other settings
});
#### resetDefaultSettings()
Resets the device settings back to default.
`typescript`
await awtrix.resetDefaultSettings();
#### erase()
Factory resets the device. Does not modify WiFi settings.
`typescript`
await awtrix.erase();
#### screen()
Get the current screen content.
`typescript`
const screen = await awtrix.screen();
#### stats()
Retrieve device statistics.
`typescript`
console.log(await awtrix.stats());
#### effects()
List available effects.
`typescript`
const effects = await awtrix.effects();
#### transitions()
List available transitions.
`typescript`
const transitions = await awtrix.transitions();
#### loop()
Get the app loop configuration.
`typescript`
console.log(await awtrix.loop());
#### playMelody(rtttl: string)
Play a melody using RTTTL format.
`typescript`
await awtrix.playMelody('d=4,o=5,b=140:c6,e6,g6');
#### playMelodyFile(name: string)
Play a melody file by name.
`typescript`
await awtrix.playMelodyFile('melody.mp3');
#### setIndicator(indicator: IndicatorPayload)
Set an indicator LED.
`typescript`
await awtrix.setIndicator({
color: [255, 0, 0],
position: awtrix.Indicators.UpperRight,
// blink: 500,
// fade: 1000,
});
#### clearIndicator(indicator: Indicators)
Clear an indicator LED.
`typescript`
await awtrix.clearIndicator(awtrix.Indicators.UpperRight);
#### moodlight(setting: MoodlightColor | MoodlightKelvin)
Set moodlight color or temperature.
`typescript`
await awtrix.moodlight({ brightness: 170, kelvin: 2300 });
`typescript`
await awtrix.moodlight({ brightness: 170, color: '#FF00FF' });
#### clearMoodlight()
Turn off moodlight.
`typescript`
await awtrix.clearMoodlight();
#### notify(notification: Interaction)
Send a notification.
`typescript`
await awtrix.notify({
text: 'Hello World!',
icon: '3049',
pushIcon: awtrix.PushIcon.MoveOnce,
effect: awtrix.Effects.PlasmaCloud,
repeat: 5,
});
#### dismissNotification()
Dismiss the current notification.
`typescript`
await awtrix.dismissNotification();
#### app(name: string, app: Interaction)
Send a custom app payload.
`typescript`
await awtrix.app('demoApp', {
text: 'This is a custom app!',
icon: '1000',
repeat: 5,
duration: 3000,
effect: awtrix.Effects.TwinklingStars,
scrollSpeed: 150,
});
#### launchApp(name: string)
Launch an app by name.
`typescript`
await awtrix.launchApp('demoApp');
#### nextApp(), previousApp()
Switch between apps.
`typescript`
await awtrix.nextApp();
await setTimeout(2000);
await awtrix.previousApp();
#### deleteApp(name: string)
Delete a custom app.
`typescript`
await clock.deleteApp('myApp');
#### Progress Bar Example
Display a progress bar using a custom app:
`typescript${i}%
for (let i = 0; i <= 100; i++) {
if (i % 5 === 0) {
await awtrix.app('Progress', {
text: ,`
progress: i,
duration: 1,
});
if (i === 0) {
await awtrix.launchApp('Progress');
}
if (i === 100) {
await awtrix.app('Progress', {
text: 'Done!',
color: [0, 255, 0],
});
}
await setTimeout(500);
}
}
#### Draw Pixels
Draw shapes on the display:
`typescript``
await clock.notify({
draw: [
new clock.draw.Pixel(0, 0, [255, 0, 0]),
new clock.draw.Line(0, 1, 15, 1, [0, 255, 0]),
new clock.draw.Rectangle(2, 2, 12, 6, [0, 0, 255]),
new clock.draw.FilledRectangle(3, 3, 10, 4, [255, 255, 0]),
new clock.draw.Circle(8, 1, 3, [0, 255, 255]),
new clock.draw.FilledCircle(8, 3, 2, [255, 0, 255]),
new clock.draw.Text(0, 1, 'AWTRIX', [255, 255, 255]),
],
});
- All API calls are asynchronous and return Promises.
- The class exposes enums for transitions, indicators, and effects for convenience.