npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

turing-pi-js

v1.1.1

Published

Fetch library for Turing Pi 2 BMC API

Downloads

8

Readme

🤖 turing-pi-js

A JavaScript client for Turing Pi web API

ℹ️ Overview

📦 Prerequisites

This project is maintained by @PhearZero and is not associated with @turing-machines. This library is used to control a Turing Pi 2 from a JavaScript environment.

⚙️ Getting started

Install

npm -i turing-pi-js --save

Import

import {tpi} from 'turing-pi-js'
const BMC_API = '<Add-URL-to-BMC-API>'
const client = tpi(BMC_API)

Example Usage

// Get current power state for all Nodes
client.get('power').then(r=>console.log(r))
// Power On Node 1
client.set('power',{node1:1}).then(r=>console.log(r))

Find out more in the detailed usage

💾 Firmware

The current firmware, as of writing (v1.0.1, v0.1.0-ce), does not support Cross Origin Requests and requires a reverse proxy to connect from another machine. This library will work without a proxy when deployed locally on the Turing Pi Web Server

🔃 Reverse Proxy

Temporary fix until the firmware api becomes more stable. This template patches the response headers for using the library in the browser. The ENV variable for the Turing Pi BMC API is BMC_API in following template:

#/etc/nginx/templates/default.conf.template
server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;
    
    location /api/bmc {
        proxy_pass   ${BMC_API};
        proxy_hide_header Content-Type;
        add_header Content-Type application/json;
        add_header Access-Control-Allow-Origin *;
    }
}

📗 Usage

✨ Create client

import {tpi} from 'turing-pi-js'
const BMC_API = '<Add-URL-to-BMC-API>'
const client = tpi(BMC_API)

🔧 Fetch Options

client.get('nodeinfo', {
    credentials: true,
})

🔌 Power

// Valid values are "0" or "1". "0" for OFF, "1" for ON.

// Get Power for all Nodes
client.get('power').then(r=>console.log(r))

// Set Power for any number of Nodes
client.set('power', {node1: 1, node2: 0, /* node3:0, node4:0 */}).then(r=>console.log(r))

⌨️ USB

// mode: Valid values are "0" or "1". "0" for Host, "1" for Device
// node: Valid values are "0", "1", "2", "3". Relating to slots Node1-4

// Get USB state from BMC
client.get('usb').then(r=>console.log(r))

// Set Power for any number of Nodes
client.set('usb', {mode: 0, node: 0}).then(r=>console.log(r))

ℹ️ Node Info

// Get Node Info
client.get('nodeinfo').then(r=>console.log(r))

ℹ️ BMC Info

// Get BMC Info
client.get('other').then(r=>console.log(r))

📂 SD Card Info

// Get SD card info
client.get('sdcard').then(r=>console.log(r))

🔃 Reset Network

// Reset network
client.set('network', {cmd: "reset"}).then(r=>console.log(r))

💾 Update Firmware

// Get the file contents
var input = document.querySelector('input[type="file"]')
// Upload firmware
client.set('firmware', {file: input.files[0]}).then(r=>console.log(r))