Skip to content

Commit

Permalink
Update readme, add package.json dev script for raspberry pi
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieGoodson committed Jul 1, 2023
1 parent 7d3a123 commit b619cec
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 29 deletions.
47 changes: 23 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
# create-svelte
## Browser App

Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte).
The browser app uses a pub/sub model to listen for messages from the Raspberry Pi.

## Creating a project
### Prerequisites

If you're seeing this, you've probably already done this step. Congrats!
- Copy `.env.example` to `.env` and fill in the values.
- Run `npm install`

```bash
# create a new project in the current directory
npm create svelte@latest
### Dev

# create a new project in my-app
npm create svelte@latest my-app
```

## Developing
- Run `npm run dev`

Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
### Production

```bash
npm run dev
- Run `npm run build`
- Serve preview via `npm run preview`

# or start the server and open the app in a new browser tab
npm run dev -- --open
```
## Raspberry Pi

## Building
- cd `raspberrypi/`
- Run `npm install`

To create a production version of your app:
Add this to your raspotify config file:

```bash
npm run build
```
OPTIONS="--onevent 'node ~/path/to/gatefold/raspberrypi/main.js'"
```

### Dev

- Run `npm run dev` to publish a test message

You can preview the production build with `npm run preview`.
## Useful links

> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
- https://github.com/dtcooper/raspotify/issues/171#issuecomment-507423901
- https://github.com/librespot-org/librespot/blob/aa880f8888226a8e5fc6e1e54dfb7cf58176ac95/src/player_event_handler.rs
5 changes: 3 additions & 2 deletions raspberrypi/main.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
var mqtt = require('mqtt');
var client = mqtt.connect('ws://broker.emqx.io:8083/mqtt');
var devMode = true;

client.on('connect', function () {
console.log('MQTT: connect');

var message;
if (devMode) {
if (process.env.DEV_MODE) {
message = {
playerEvent: 'start',
trackId: '2sCaihW0VlDKecbUgMSzRY'
Expand All @@ -20,5 +19,7 @@ client.on('connect', function () {
}

client.publish('librespot/playerEvent', JSON.stringify(message));
console.log('MQTT: published');
console.log(message);
client.end();
});
6 changes: 4 additions & 2 deletions raspberrypi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {},
"scripts": {
"dev": "DEV_MODE=true node ./main.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"mqtt": "^4.3.7"
}
}
}
2 changes: 1 addition & 1 deletion src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
console.log(`MQTT: ${message}`);
if (!message || message == '{}') {
console.error('MQTT: Empty message. Aborting.');
console.warn('MQTT: Empty message. Ignoring...');
return;
}
Expand Down

0 comments on commit b619cec

Please sign in to comment.