Skip to content

Arduino project to execute API calls and WebSocket commands

Notifications You must be signed in to change notification settings

edememinov/MacroDeck

Repository files navigation

MacroDeck

Goal

The goal of this project was to replicate a StreamDeck as closely as possible using an Arduino(clone).

Function of the device

This project can execute API calls and Websocket commands. A txt file in JSON format can be loaded unto the Arduino SPIFFS memory which will contain the commands for the calls & commands. Each file contains multiple pages (Up to 8 pages because of the RAM limitations) and each page contains up to 15 buttons. It is possible to swap between files by pressing button 16 and selecting the page by pressing the corresponding button. While creating/editing the JSON files with buttons and pages the order matters. The order on the page/button corresponds with the button number. For example 6th button on the page can be selected by pressing button number 6.

Using the device

Connecting to WiFi

When the software boots it will start to look for WiFi access points that are stored in its memory. If none are found the Arduino will go into AP mode and create an AP called "MacroBoardWifiConnect". After connecting to "MacroBoardWifiConnect" visit the following ip-address: 192.168.4.1. There a WiFi AP can be chosen to connect to.

Configuring the device

The following variables can be set in the config.txt file:

{
	"fingerprint" : "global SSL fingerprint",
	"socketHost" : "IP address of the PC which is running DeckBoard",
	"socketPort" : "DeckBoard port is always 8500",
	"development": true
}

Side note: .json files are not supported by the system.

Using the Web Interface

After the device is connected to WiFi a server ip-address will be displayed. Opening the ip-address in browser will open the web-interface. With this interface files can be uploaded, downloaded and deleted from the Arduino. Furthermore a page to check free SPIFFS space is available.

Executing WebSocket commands.

To execute WebSocket commands this project heavily relies on Deckboard. After installing Deckboard a script can be run to download the Deckboard button configuration. This script will get all available buttons and write them in the correct JSON format. Afterwards these buttons can be copy-pasted into a file used by Macro Board. The button type should be a "socket" in this case.

Please note that if you are using DeckBoard Pro features, you should buy the DeckBoard Pro app from the Android Play Store, to support the developer.

{
	"pages":
		[
			{
				"name":"Page name",
				"buttons":
				[
				
					 {
						"command_id": 27,
						"type": "socket",
						"description": "Button Description"
					}
				]
			}	
		]
}

			

command_id is the Deckboard id for the command. If generated through the node js script, this will be filled automatically

Executing API calls

API Calls will be handled just like WebSocket commands. An example of a button which will handle an API Call can be found below.

{
	"pages":
		[
			{
				"name":"Page name",
				"buttons":
				[
					 {
						"url": "http://url-to-the-api.com/getSomethingFromAPI",
						"type": "apiCall",
						"description": "Button Description",
            					"fingerprint":"optional SSL fingerprint. It can also be set globally in config.txt"
					}
				]
			}	
		]
}

			

Get the website's SSL fingerprint certificate

Parts used

For this project the following items were used:

Optional:

Schematics

Below is a table which shows how the Wemos D1 R1 is connected to the other components

Wemos D1 R1 Pins Screen Pin
D12/MISO/D6 SDO/MISO
5V LED
D13/SCK/D5 SCK
D11/MOSI/D7 SDI/MOSI
D15/SCL/D3 DC/RS
D14/SDA/D4 RESET
D8 CS
GND GND
5V VCC
Wemos D1 R1 Pins Keypad Pin
A0 Out
3.3V VCC
GND GND

TFT_eSPI options

User_Setup.h is needed to make the screen work. It holds the configuration and pin definitions. It will be added to this repo and has to be pasted to ~/Documents/Arduino/libraries/TFT_eSPI/User_Setup.h

Other projects used within this project

How to get Deckboard data

  • Open deckboard_getData folder.
  • Run "npm install"
  • Run "node index.js"
  • Wait for it to finish. This should take around 5 seconds.
  • Press ctr+c to force quit.
  • Run "node merge-files.js"

The folder finalData will contain finalButton.json, this file contains all the deckboard buttons with a name.

Roadmap

  • 3-D printed case for the MacroBoard
  • Bug fixes (none are known atm)
  • Improvements to user-experience
  • Code clean-up
  • Windows app to set up buttons and pages .txt file
  • Adding an Arduino Nano to read out the battery percentage

Useful information on programming for ESP8266 (Wemos D1 R1)