Skip to content

labatrockwell/spacebrew-arduino-library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

steps

Click the DOWNLOADS button in the top right corner, rename the uncompressed folder Spacebrew. Check that the Spacebrew folder contains Spacebrew.cpp and Spacebrew.h

Place the Spacebrew library folder your /libraries/ folder. You may need to create the libraries subfolder if its your first library.

Also download and install the WebSocketClient library from https://github.com/labatrockwell/ArduinoWebsocketClient

Restart the IDE.

includes

These should be placed at the top of your sketch:

#include <SPI.h>
#include <Spacebrew.h>
#include <Ethernet.h>
#include <WebSocketClient.h>

setup

  • At the top of the file:
    • Spacebrew sb;
  • In setup:
    • Ethernet.start(mac);//as per the Ethernet library example, where mac is a byte[6]
  • In loop:
    • sb.monitor();

usage

publishing

  • range:
    • sb.addPublish("PubName", RANGE);
    • sb.addPublish("OtherPubName", 255);
  • string:
    • sb.addPublish("PubStringName", STRING);
    • sb.addPublish("AnotherStringOutput", "default string");
  • boolean:
    • sb.addPublish("BoolPub", BOOLEAN);
    • sb.addPublish("Different_Bool", true);
  • other:
    • sb.addPublish("Custom Publisher", "img_url");

subscribing

  • range:
    • sb.addSubscribe("SubName", RANGE);
    • sb.addSubscribe("OtherSubName", "range");
  • string:
    • sb.addSubscribe("SubStringName", STRING);
    • sb.addSubscribe("AnotherStringInput", "string");
  • boolean:
    • sb.addSubscribe("BoolSub", BOOLEAN);
    • sb.addSubscribe("Different_Bool", "boolean");
  • other:
    • sb.addSubscribe("Custom Subscriber", "crazy_type");

receving messages from subscribers

  • range: sb.onRangeMessage(receivedRange); and then...
    void receivedRange(char* name, int value){
        Serial.print("[onRangeMessage]");
        Serial.print(name);
        Serial.print(": ");
        Serial.println(value);
    }
  • string: sb.onStringMessage(receivedString); and then...
    void receivedString(char* name, char* value){
        Serial.print("[onStringMessage]");
        Serial.print(name);
        Serial.print(": ");
        Serial.println(value);
    }
  • boolean: sb.onBooleanMessage(receivedBool); and then...
    void receivedBool(char* name, bool value){
        Serial.print("[onBoolMessage]");
        Serial.print(name);
        Serial.print(": ");
        Serial.println(value ? "true" : "false);
    }
  • other: sb.onOtherMessage(receivedOther); and then...
    void receivedOther(char* name, char* value){
        Serial.print("[onOtherMessage]");
        Serial.print(name);
        Serial.print(": ");
        Serial.println(value);
    }

connecting to a server

uint8_t mac[] = {0xa4, 0xe7, 0xee, 0x03, 0xfd, 0x32};
Ethernet.begin(mac);
sb.connect("sandbox.spacebrew.cc", "Rename_Me", "Inputs and Outputs?");

Where:

  • mac: the mac address for the Ethernet library to get an IP, may need to be unique
  • "sandbox.spacebrew.cc": the address for the computer where you are running the spacebrew server
  • "Rename_Me": the name for this client
  • "Inputs and Outputs?": a description for this client which will be exposed via the admin

sending messages via publishers

  • range: sb.send("myRangePub", 255);
  • string: sb.send("someStringOutput", "bang!");
  • boolean: sb.send("myBoolPub", true);
  • other: sb.send("customOutput", "img_url", "http://nyopoliticker.files.wordpress.com/2012/08/614px-hallandoatesalbumcover.jpeg");

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages