
I'm pleased to announce the first alpha release of steemduino - an Arduino library for accessing the steem web socket API.
What is steemduino?
steemduino allows you to communicate with the Steem websocket API using an Arduino, the open source electronics platform.



You can use the library to monitor incoming blocks and perform actions depending on the contents, such as displaying a message on an LCD screen or sounding an alarm.
With steemduino you can create a custom notification system that will alert you to anything that's happening in the steem blockchain. In future, as more functionality is added, the only limitations will be your imagination.
What's an alpha release?
An alpha release is a release where the code is still experimental and probably contains bugs. There are a lot of areas in steemduino that can be improved, but releasing the library allows me to get feedback and contributions from the community.
The number one big issue is memory use. The web socket library used by steemduino tries to load responses into memory, and since the Arduino doesn't have very much, blocks containing large posts or comments will fail. You've been warned.
The second issues on the list is functionality. At the moment its limited to getting blocks by their block number. You can already achieve a lot with this, but adding access to additional RPC methods will make it much more flexible.
Hardware requirements
steemduino was developed on the Arduino Mega 2560 and I recommend you use this. It's unlikely that anything will work on boards with less SRAM and Flash Memory, and it's not been tested on
All the examples use an Ethernet Shield to connect to The Internet. You can also try a WiFi shield, but this hasn't been tested and the examples will need adjusting.
Note: If you decide to use an Ethernet Shield, check carefully that it's compatible with an Arduino Mega. Not all version are.
Installation
Currently steemduino and its dependencies must be installed manually. You can download them from the links below:
The LED matrix examples depend on the following library:
All examples come with a makefile for building the project using Arduino-Makefile. With this you can avoid using the awful Arduino IDE.
Quick guide
This section will very quickly cover how the library works. In future posts I'll cover more specific tasks and components.
Each program you will have the following:
- An instance of
SteemRpc
for accessing the steem web socket API - An instance of
JsonStreamingParser
andOpListener
for parsing blocks; - An op handler function for processing parsed blocks.
The code below is a skeleton you can use when beginning a project. It contains all the code you need to do all the steps above.
#include
#include
#include
#include
#include
EthernetClient client = EthernetClient();
SteemRpc steem(client, "node.steem.ws", "/", 80);
unsigned long current_block = 0;
void op_handler(const String& op_type, const String& op_data) {
Serial.println(op_type);
}
void setup() {
Serial.begin(9600);
Serial.println("Connecting to network");
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
Ethernet.begin(mac);
Serial.println("Connecting to Steem web socket");
if (steem.connect()) {
Serial.println("Connected to Steem web socket");
} else {
Serial.println("Failed to connect to Steem websocket");
while (1) {};
}
}
void loop() {
// Hang if the client disconnects
if (!steem.is_connected()) {
Serial.println("Client disconnected");
while (1) {}
}
// Get the last block number
unsigned long last_block = steem.get_last_block_num();
if (current_block == 0) current_block = last_block;
while (current_block <= last_block) {
// Get the block
String block = "";
if (!steem.get_block(current_block, block)) {
Serial.print("Failed to get block ");
Serial.println(current_block);
continue;
}
// Parse the block
JsonStreamingParser parser;
OpListener listener(&op_handler);
parser.setListener(&listener);
const char* block_c = block.c_str();
for (size_t i = 0; i < strlen(block_c); ++i) {
parser.parse(block_c[i]);
}
current_block += 1;
}
delay(5000);
}
For more information see the examples provided with the library. If you really get stuck and need help, you're welcome to come at chat with me on steemit.chat or open an issue on GitHub.