Skip to content
Snippets Groups Projects
Commit 6bf514b1 authored by Joe Revans's avatar Joe Revans
Browse files

Wallvis -> VizBlocks

parent 2e7d7f9b
No related branches found
No related tags found
3 merge requests!4Joe merge,!2Docs,!1Pactman/VizBlocks Merge
Showing
with 142 additions and 67 deletions
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#define BUTTON_BEHAVIOUR_h #define BUTTON_BEHAVIOUR_h
#include "Arduino.h" #include "Arduino.h"
#include "Behaviours.h" #include "Behaviours.h"
#include <WallVis.h> #include <VizBlocks.h>
class ButtonPressed : public Behaviour { class ButtonPressed : public Behaviour {
/* /*
...@@ -10,10 +10,10 @@ class ButtonPressed : public Behaviour { ...@@ -10,10 +10,10 @@ class ButtonPressed : public Behaviour {
* ButtonPressed message to the input topic of the * ButtonPressed message to the input topic of the
* MQQT broker * MQQT broker
*/ */
WallVis* _node; VizBlocks* _node;
public: public:
ButtonPressed(WallVis* node, String name = "ButtonPressed") : ButtonPressed(VizBlocks* node, String name = "ButtonPressed") :
Behaviour(name), _node(node){ } Behaviour(name), _node(node){ }
char* args() {return "<String buttonId>"; }; char* args() {return "<String buttonId>"; };
...@@ -32,10 +32,10 @@ class ButtonReleased : public Behaviour { ...@@ -32,10 +32,10 @@ class ButtonReleased : public Behaviour {
* ButtonReleased message to the input topic of the * ButtonReleased message to the input topic of the
* MQQT broker * MQQT broker
*/ */
WallVis* _node; VizBlocks* _node;
public: public:
ButtonReleased(WallVis* node, String name = "ButtonReleased") : ButtonReleased(VizBlocks* node, String name = "ButtonReleased") :
Behaviour(name), _node(node){ } Behaviour(name), _node(node){ }
char* args() {return "<String buttonId>"; }; char* args() {return "<String buttonId>"; };
...@@ -54,10 +54,10 @@ class ButtonClicked : public Behaviour { ...@@ -54,10 +54,10 @@ class ButtonClicked : public Behaviour {
* ButtonClicked message to the input topic of the * ButtonClicked message to the input topic of the
* MQQT broker * MQQT broker
*/ */
WallVis* _node; VizBlocks* _node;
public: public:
ButtonClicked(WallVis* node, String name = "ButtonClicked") : ButtonClicked(VizBlocks* node, String name = "ButtonClicked") :
Behaviour(name), _node(node){ } Behaviour(name), _node(node){ }
char* args() {return "<String buttonId>"; }; char* args() {return "<String buttonId>"; };
...@@ -76,10 +76,10 @@ class ButtonHeld : public Behaviour { ...@@ -76,10 +76,10 @@ class ButtonHeld : public Behaviour {
* ButtonLongPressed message to the input topic of the * ButtonLongPressed message to the input topic of the
* MQQT broker * MQQT broker
*/ */
WallVis* _node; VizBlocks* _node;
public: public:
ButtonHeld(WallVis* node, String name = "ButtonHeld") : ButtonHeld(VizBlocks* node, String name = "ButtonHeld") :
Behaviour(name), _node(node){ } Behaviour(name), _node(node){ }
char* args() {return "<String buttonId>"; }; char* args() {return "<String buttonId>"; };
...@@ -98,10 +98,10 @@ class ButtonTick : public Behaviour { ...@@ -98,10 +98,10 @@ class ButtonTick : public Behaviour {
* ButtonRepeatPressed message to the input topic of the * ButtonRepeatPressed message to the input topic of the
* MQQT broker * MQQT broker
*/ */
WallVis* _node; VizBlocks* _node;
public: public:
ButtonTick(WallVis* node, String name = "ButtonTick") : ButtonTick(VizBlocks* node, String name = "ButtonTick") :
Behaviour(name), _node(node){ } Behaviour(name), _node(node){ }
char* args() {return "<String buttonId>"; }; char* args() {return "<String buttonId>"; };
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#define COMMS_BEHAVIOUR_h #define COMMS_BEHAVIOUR_h
#include "Arduino.h" #include "Arduino.h"
#include "Behaviours.h" #include "Behaviours.h"
#include <WallVis.h> #include <VizBlocks.h>
/* /*
* -------------------------------------------------- * --------------------------------------------------
...@@ -11,10 +11,10 @@ ...@@ -11,10 +11,10 @@
*/ */
class SendCapabilities : public Behaviour { class SendCapabilities : public Behaviour {
WallVis* _node; VizBlocks* _node;
public: public:
SendCapabilities(WallVis* node, String name = "SendCapabilities") : SendCapabilities(VizBlocks* node, String name = "SendCapabilities") :
Behaviour(name), _node(node){ } Behaviour(name), _node(node){ }
String start(String args) { String start(String args) {
...@@ -32,13 +32,13 @@ public: ...@@ -32,13 +32,13 @@ public:
*/ */
class Link : public Behaviour { class Link : public Behaviour {
WallVis* _node; VizBlocks* _node;
String _peerId; String _peerId;
const int _timeoutInterval = 5000; const int _timeoutInterval = 5000;
unsigned long _t = 0; unsigned long _t = 0;
public: public:
Link(WallVis* node, String name = "Link") : Behaviour(name), _node(node) { _background = true; } Link(VizBlocks* node, String name = "Link") : Behaviour(name), _node(node) { _background = true; }
char* args() {return "<String peerId>"; }; char* args() {return "<String peerId>"; };
...@@ -80,13 +80,13 @@ public: ...@@ -80,13 +80,13 @@ public:
*/ */
class PingServer : public Behaviour { class PingServer : public Behaviour {
WallVis* _node; VizBlocks* _node;
String str; String str;
const int _interval = 4000; const int _interval = 4000;
unsigned long _t = 0; unsigned long _t = 0;
public: public:
PingServer(WallVis* node, String name = "PingServer") : Behaviour(name), _node(node) { _background = true; } PingServer(VizBlocks* node, String name = "PingServer") : Behaviour(name), _node(node) { _background = true; }
String start(String args) { String start(String args) {
_background = true; _background = true;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#define POTENTIOMETER_BEHAVIOUR_h #define POTENTIOMETER_BEHAVIOUR_h
#include "Arduino.h" #include "Arduino.h"
#include "Behaviours.h" #include "Behaviours.h"
#include <WallVis.h> #include <VizBlocks.h>
class PotentiometerUpdated : public Behaviour { class PotentiometerUpdated : public Behaviour {
/* /*
...@@ -10,10 +10,10 @@ class PotentiometerUpdated : public Behaviour { ...@@ -10,10 +10,10 @@ class PotentiometerUpdated : public Behaviour {
* ButtonPressed message to the input topic of the * ButtonPressed message to the input topic of the
* MQQT broker * MQQT broker
*/ */
WallVis* _node; VizBlocks* _node;
public: public:
PotentiometerUpdated(WallVis* node, String name = "PotentiometerUpdated") : PotentiometerUpdated(VizBlocks* node, String name = "PotentiometerUpdated") :
Behaviour(name), _node(node){ } Behaviour(name), _node(node){ }
char* args() {return "<String potentiometerId> <int value>"; }; char* args() {return "<String potentiometerId> <int value>"; };
......
# Wallvis Framework # VizBlocks Framework
This is an Arduino library that lets you easily create nodes to stick on the wall. Each node will listen on an MQTT channel, and respond to commands. So a node with a servo motor in might respond to: This is an Arduino library that lets you easily create nodes to stick on the wall. Each node will listen on an MQTT channel, and respond to commands. So a node with a servo motor in might respond to:
* `wiggle 30` - wiggle by 30 degrees a few times * `wiggle 30` - wiggle by 30 degrees a few times
...@@ -7,9 +7,9 @@ These commands can be put in via NodeRED, or through the USB Serial connection f ...@@ -7,9 +7,9 @@ These commands can be put in via NodeRED, or through the USB Serial connection f
## Installation ## Installation
One way to install this is put it in you personal Arduino libraries directory. On a mac, this is `~/Documents/Arduino/libraries`. It is best to check it out with a capitalised name, i.e. `WallvisFramework` not `wallvisframework`. To do this, you can use: One way to install this is put it in you personal Arduino libraries directory. On a mac, this is `~/Documents/Arduino/libraries`. It is best to check it out with a capitalised name, i.e. `VizBlocksFramework` not `VizBlocksframework`. To do this, you can use:
`git clone https://git.ecdf.ed.ac.uk/design-informatics/wallvis/wallvisframework.git WallvisFramework` `git clone https://git.ecdf.ed.ac.uk/design-informatics/VizBlocks/VizBlocksframework.git VizBlocksFramework`
The library will then appear in your list of Arduino libraries, along with examples. The library will then appear in your list of Arduino libraries, along with examples.
...@@ -26,18 +26,18 @@ Because this is not a single sketch, development needs a bit of thinking about. ...@@ -26,18 +26,18 @@ Because this is not a single sketch, development needs a bit of thinking about.
# Usage # Usage
The library is designed to be used within normal Arduino sketches. It wraps up most of the business of connecting to MQTT etc. in a `WallVis` class, and you then give it a bunch of `Behaviours` that do interesting things. The library is designed to be used within normal Arduino sketches. It wraps up most of the business of connecting to MQTT etc. in a `VizBlocks` class, and you then give it a bunch of `Behaviours` that do interesting things.
## Setup ## Setup
The node is set up with all of the connection information for the WiFi network and for NodeRE, e.g.: The node is set up with all of the connection information for the WiFi network and for NodeRE, e.g.:
```arduino ```arduino
#include <WallVis.h> #include <VizBlocks.h>
WallVis node( VizBlocks node(
"new001", // Our ID "new001", // Our ID
"WallVisNet", //Wifi Access Point "VizBlocksNet", //Wifi Access Point
"wallvisAP", //WiFi Password "VizBlocksAP", //WiFi Password
"192.168.4.1",//IP address of Node RED server "192.168.4.1",//IP address of Node RED server
1883 //Port for Node RED server 1883 //Port for Node RED server
); );
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#define ROTARYENCODER_BEHAVIOUR_h #define ROTARYENCODER_BEHAVIOUR_h
#include "Arduino.h" #include "Arduino.h"
#include "Behaviours.h" #include "Behaviours.h"
#include <WallVis.h> #include <VizBlocks.h>
class RotaryEncoderUpdated : public Behaviour { class RotaryEncoderUpdated : public Behaviour {
/* /*
...@@ -10,10 +10,10 @@ class RotaryEncoderUpdated : public Behaviour { ...@@ -10,10 +10,10 @@ class RotaryEncoderUpdated : public Behaviour {
* ButtonPressed message to the input topic of the * ButtonPressed message to the input topic of the
* MQQT broker * MQQT broker
*/ */
WallVis* _node; VizBlocks* _node;
public: public:
RotaryEncoderUpdated(WallVis* node, String name = "RotaryEncoderUpdated") : RotaryEncoderUpdated(VizBlocks* node, String name = "RotaryEncoderUpdated") :
Behaviour(name), _node(node){ } Behaviour(name), _node(node){ }
char* args() {return "<String rotaryEncoderId> <int position>"; }; char* args() {return "<String rotaryEncoderId> <int position>"; };
......
File moved
#ifndef WALLVIS_H #ifndef VizBlocks_H
#define WALLVIS_H #define VizBlocks_H
#include "Arduino.h" #include "Arduino.h"
#include "Behaviours.h" #include "Behaviours.h"
#include "ServoBehaviours.h" #include "ServoBehaviours.h"
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#define MQTT_topic "new001" #define MQTT_topic "new001"
#define NUM_BACKGROUND_BEHAVIOURS 5 #define NUM_BACKGROUND_BEHAVIOURS 5
class WallVis { class VizBlocks {
char* _ssid; char* _ssid;
char* _wifi_pass; char* _wifi_pass;
char* _id; char* _id;
...@@ -39,7 +39,7 @@ class WallVis { ...@@ -39,7 +39,7 @@ class WallVis {
String capabilitiesJSON[50]; String capabilitiesJSON[50];
public: public:
WallVis(char* id, char* ssid="WallVisNet", char* wifi_pass="wallvisAP", VizBlocks(char* id, char* ssid="VizBlocksNet", char* wifi_pass="VizBlocksAP",
char* server="172.20.10.8",int port=1883) : _id(id), _server(server), _port(port), _ssid(ssid), _wifi_pass(wifi_pass) {} ; char* server="172.20.10.8",int port=1883) : _id(id), _server(server), _port(port), _ssid(ssid), _wifi_pass(wifi_pass) {} ;
void command_callback(char *data, uint16_t len) { void command_callback(char *data, uint16_t len) {
...@@ -50,12 +50,12 @@ public: ...@@ -50,12 +50,12 @@ public:
void set_wifi(boolean v) { _wifi = v; } void set_wifi(boolean v) { _wifi = v; }
/* /*
* Set up the WallVis node - WiFi, MQTT * Set up the VizBlocks node - WiFi, MQTT
*/ */
void init() { void init() {
Serial.setTimeout(100); Serial.setTimeout(100);
Serial.println(); Serial.println();
Serial.println(F("WallVis Node starting up")); Serial.println(F("VizBlocks Node starting up"));
Serial.println("Initialising " + String(_id)); Serial.println("Initialising " + String(_id));
if( _wifi ) { if( _wifi ) {
...@@ -112,7 +112,7 @@ public: ...@@ -112,7 +112,7 @@ public:
* this function is the only thing you should need to call. It will manage * this function is the only thing you should need to call. It will manage
* it's own delay, so you can call as often as possible. * it's own delay, so you can call as often as possible.
*/ */
void vis_loop() { void run() {
int loop_start_time = millis(); int loop_start_time = millis();
serial_command(); serial_command();
if( _wifi ) { mqtt_command(); } if( _wifi ) { mqtt_command(); }
...@@ -294,7 +294,7 @@ public: ...@@ -294,7 +294,7 @@ public:
}; };
/* /*
* These behaviours depend on WallVis class so they must be included after * These behaviours depend on VizBlocks class so they must be included after
* it has been defined. * it has been defined.
*/ */
#include "CommsBehaviours.h" #include "CommsBehaviours.h"
......
#include <WallVis.h> #include <VizBlocks.h>
#include <Behaviours.h> #include <Behaviours.h>
WallVis node( VizBlocks node(
"new001", // Our ID "new001", // Our ID
"WallVisNet", //Wifi Access Point "VizBlocksNet", //Wifi Access Point
"wallvisAP", //WiFi Password "VizBlocksAP", //WiFi Password
"192.168.4.1",//IP address of Node RED server "192.168.4.1",//IP address of Node RED server
1883 //Port for Node RED server 1883 //Port for Node RED server
); );
......
...@@ -26,7 +26,7 @@ void loop() { ...@@ -26,7 +26,7 @@ void loop() {
void cb(Button* button, uint8_t eventType, bool state) { void cb(Button* button, uint8_t eventType, bool state) {
/* /*
* Rotary Encoder event handler that triggers WallVis behaviours * Rotary Encoder event handler that triggers VizBlocks behaviours
*/ */
String idString = String(button->getId()); String idString = String(button->getId());
......
...@@ -21,7 +21,7 @@ void loop() { ...@@ -21,7 +21,7 @@ void loop() {
void cb(Potentiometer* potentiometer, uint8_t eventType, uint8_t sensorValue) { void cb(Potentiometer* potentiometer, uint8_t eventType, uint8_t sensorValue) {
/* /*
* Potentiometer Event Handler that triggers WallVis behaviours * Potentiometer Event Handler that triggers VizBlocks behaviours
*/ */
String idString = String(potentiometer->getId()); String idString = String(potentiometer->getId());
......
...@@ -26,7 +26,7 @@ void loop() { ...@@ -26,7 +26,7 @@ void loop() {
void cb(RotaryEncoder* rotaryEncoder, uint8_t eventType, int position) { void cb(RotaryEncoder* rotaryEncoder, uint8_t eventType, int position) {
/* /*
* Rotary Encoder event handler that triggers WallVis behaviours * Rotary Encoder event handler that triggers VizBlocks behaviours
*/ */
String idString = String(rotaryEncoder->getId()); String idString = String(rotaryEncoder->getId());
......
#include <Servo.h> #include <Servo.h>
#include <WallVis.h> #include <VizBlocks.h>
WallVis node( VizBlocks node(
"new001", // Our ID "new001", // Our ID
"NodeRedServer", //Wifi Access Point "NodeRedServer", //Wifi Access Point
"NodeR3dAP", //WiFi Password "NodeR3dAP", //WiFi Password
......
#include "NameDictionary.h" #include "NameDictionary.h"
#include <Servo.h> #include <Servo.h>
#include <WallVis.h> #include <VizBlocks.h>
//Get device name //Get device name
const String device_id = String(ESP.getChipId(), HEX); const String device_id = String(ESP.getChipId(), HEX);
...@@ -16,7 +16,7 @@ Servo s1 = Servo(); ...@@ -16,7 +16,7 @@ Servo s1 = Servo();
#define LED_PIN D2 #define LED_PIN D2
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
WallVis node( VizBlocks node(
"null", // Our ID "null", // Our ID
"NodeRedServer", //Wifi Access Point "NodeRedServer", //Wifi Access Point
"NodeR3dAP", //WiFi Password "NodeR3dAP", //WiFi Password
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include "Button.h" #include "Button.h"
#include "Potentiometer.h" #include "Potentiometer.h"
#include "RotaryEncoder.h" #include "RotaryEncoder.h"
#include "WallVis.h" #include "VizBlocks.h"
#include "Behaviours.h" #include "Behaviours.h"
//Get device name //Get device name
...@@ -27,8 +27,8 @@ const int rePinB = 5; ...@@ -27,8 +27,8 @@ const int rePinB = 5;
const int reID = 2; const int reID = 2;
RotaryEncoder re(rePinA, rePinB, reID); RotaryEncoder re(rePinA, rePinB, reID);
//Construct WallVis //Construct VizBlocks
WallVis node( VizBlocks node(
"null", // Our ID "null", // Our ID
"NodeRedServer", //Wifi Access Point "NodeRedServer", //Wifi Access Point
"NodeR3dAP", //WiFi Password "NodeR3dAP", //WiFi Password
...@@ -102,7 +102,7 @@ void loop() { ...@@ -102,7 +102,7 @@ void loop() {
void bCB(Button* button, uint8_t eventType, bool state) { void bCB(Button* button, uint8_t eventType, bool state) {
/* /*
* Button event handler that triggers WallVis behaviours * Button event handler that triggers VizBlocks behaviours
*/ */
String idString = String(button->getId()); String idString = String(button->getId());
...@@ -138,7 +138,7 @@ void bCB(Button* button, uint8_t eventType, bool state) { ...@@ -138,7 +138,7 @@ void bCB(Button* button, uint8_t eventType, bool state) {
void pCB(Potentiometer* potentiometer, uint8_t eventType, uint8_t sensorValue) { void pCB(Potentiometer* potentiometer, uint8_t eventType, uint8_t sensorValue) {
/* /*
* Potentiometer Event Handler that triggers WallVis behaviours * Potentiometer Event Handler that triggers VizBlocks behaviours
*/ */
String idString = String(potentiometer->getId()); String idString = String(potentiometer->getId());
...@@ -159,7 +159,7 @@ void pCB(Potentiometer* potentiometer, uint8_t eventType, uint8_t sensorValue) { ...@@ -159,7 +159,7 @@ void pCB(Potentiometer* potentiometer, uint8_t eventType, uint8_t sensorValue) {
void reCB(RotaryEncoder* rotaryEncoder, uint8_t eventType, int position) { void reCB(RotaryEncoder* rotaryEncoder, uint8_t eventType, int position) {
/* /*
* Rotary Encoder event handler that triggers WallVis behaviours * Rotary Encoder event handler that triggers VizBlocks behaviours
*/ */
String idString = String(rotaryEncoder->getId()); String idString = String(rotaryEncoder->getId());
......
#include <WallVis.h> #include <VizBlocks.h>
#include <Behaviours.h> #include <Behaviours.h>
WallVis node( VizBlocks node(
"new001", // Our ID "new001", // Our ID
"WallVisNet", //Wifi Access Point "VizBlocksNet", //Wifi Access Point
"wallvisAP", //WiFi Password "VizBlocksAP", //WiFi Password
"192.168.4.1",//IP address of Node RED server "192.168.4.1",//IP address of Node RED server
1883 //Port for Node RED server 1883 //Port for Node RED server
); );
......
#include <Servo.h> #include <Servo.h>
#include <WallVis.h> #include <VizBlocks.h>
WallVis node( VizBlocks node(
"new001", // Our ID "new001", // Our ID
"WallVisNet", //Wifi Access Point "VizBlocksNet", //Wifi Access Point
"wallvisAP", //WiFi Password "VizBlocksAP", //WiFi Password
"192.168.4.1",//IP address of Node RED server "192.168.4.1",//IP address of Node RED server
1883 //Port for Node RED server 1883 //Port for Node RED server
); );
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
#include <AdjustableButtonConfig.h> #include <AdjustableButtonConfig.h>
#include <ButtonConfig.h> #include <ButtonConfig.h>
#include <WallVis.h> #include <VizBlocks.h>
WallVis node( VizBlocks node(
"new001", // Our ID "new001", // Our ID
"JR", //Wifi Access Point "JR", //Wifi Access Point
"hotsp0t2", //WiFi Password "hotsp0t2", //WiFi Password
......
#include "NameDictionary.h"
#include <VizBlocks.h>
#include <Behaviours.h>
//Get device name
const String device_id = String(ESP.getChipId(), HEX);
NameDictionary d;
const String id = d.get(device_id);
char _id[10];
//Init as a VizBlock node with "null" ID.
VizBlocks node(
"null", // Our ID
"NodeRedServer", //Wifi Access Point
"NodeR3dAP", //WiFi Password
"192.168.4.1",//IP address of Node RED server
1883 //Port for Node RED server
);
unsigned long t = 0;
const int pingInterval = 4000;
void setup()
{
//Get the serial port ready
Serial.begin(115200);
Serial.println("Serial started!");
delay(500);
//Print device name
if (id == device_id) {
Serial.println("!!! This device doesn't have a name yet. Let's call it: " + id);
} else {
Serial.println("Device name: " + id);
}
id.toCharArray(_id, 10);
node.setID(_id);
//Add in the custom behaviour we defined earlier.
node.add(new SendCapabilities(&node) );
node.add(new PingServer(&node) );
node.add(new Link(&node) );
node.add(new ButtonPressed(&node) );
node.add(new ButtonReleased(&node) );
node.add(new ButtonClicked(&node) );
node.add(new ButtonHeld(&node) );
node.add(new ButtonTick(&node) );
node.add(new PotentiometerUpdated(&node) );
node.add(new RotaryEncoderUpdated(&node) );
//Initialise the whole infrastructure
node.set_wifi(true);
node.init();
delay(500);
node.process("PingServer");
}
void loop()
{
node.run();
pingComms(pingInterval);
}
void pingComms(int interval) {
unsigned long timeNow = millis();
if (timeNow > t + interval) {
t = timeNow;
Serial.println("Link " + id);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment