Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
VizBlocksFramework
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Design Informatics
VizBlocks
VizBlocksFramework
Commits
16711d73
Commit
16711d73
authored
5 years ago
by
Joe Revans
Browse files
Options
Downloads
Patches
Plain Diff
Annouce Capabilities
parent
9fa037e0
No related branches found
No related tags found
3 merge requests
!4
Joe merge
,
!2
Docs
,
!1
Pactman/VizBlocks Merge
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
WallVis.h
+35
-14
35 additions, 14 deletions
WallVis.h
with
35 additions
and
14 deletions
WallVis.h
+
35
−
14
View file @
16711d73
...
@@ -34,6 +34,8 @@ class WallVis {
...
@@ -34,6 +34,8 @@ class WallVis {
WiFiClient
*
_client
;
WiFiClient
*
_client
;
boolean
_wifi
;
boolean
_wifi
;
String
capabilitiesJSON
[
50
];
public:
public:
WallVis
(
char
*
id
,
char
*
ssid
=
"WallVisNet"
,
char
*
wifi_pass
=
"wallvisAP"
,
WallVis
(
char
*
id
,
char
*
ssid
=
"WallVisNet"
,
char
*
wifi_pass
=
"wallvisAP"
,
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
)
{}
;
...
@@ -95,6 +97,7 @@ public:
...
@@ -95,6 +97,7 @@ public:
MQTT_connect
();
MQTT_connect
();
}
}
generateCapabilitiesJSON
();
announce_capabilities
();
announce_capabilities
();
Serial
.
println
(
"Init finished"
);
Serial
.
println
(
"Init finished"
);
...
@@ -223,15 +226,24 @@ public:
...
@@ -223,15 +226,24 @@ public:
Serial
.
println
(
"MQTT Connected!"
);
Serial
.
println
(
"MQTT Connected!"
);
}
}
void
generateCapabilitiesJSON
()
{
String
head
=
"{
\"
name
\"
:
\"
"
+
String
(
_id
)
+
"
\"
,
\"
behaviour
\"
:{"
;
for
(
int
i
=
0
;
i
<
_behaviours
.
get_num_behaviours
();
i
++
)
{
Behaviour
*
b
=
_behaviours
.
get_by_num
(
i
);
String
args
=
b
->
args
();
String
body
=
"
\"
index
\"
:
\"
"
+
String
(
i
)
+
"
\"
,
\"
name
\"
:
\"
"
+
b
->
name
()
+
"
\"
,
\"
args
\"
:
\"
"
+
args
+
"
\"
}}"
;
String
str
=
head
+
body
;
capabilitiesJSON
[
i
]
=
str
;
}
}
void
announce_capabilities
()
{
void
announce_capabilities
()
{
Serial
.
print
(
"Node "
);
String
doc
;
Serial
.
println
(
_id
);
if
(
_wifi
)
{
if
(
_wifi
)
{
if
(
!
_announce
->
publish
(
_id
)
)
{
Serial
.
println
(
"Couldn't make announcement"
);
}
if
(
!
_announce
->
publish
(
_id
)
)
{
Serial
.
println
(
"Couldn't make announcement"
);
}
}
}
for
(
int
i
=
0
;
i
<
_behaviours
.
get_num_behaviours
();
i
++
)
{
for
(
int
i
=
0
;
i
<
_behaviours
.
get_num_behaviours
();
i
++
)
{
Behaviour
*
b
=
_behaviours
.
get_by_num
(
i
);
doc
=
capabilitiesJSON
[
i
];
String
doc
=
b
->
name
()
+
": "
+
b
->
args
();
if
(
_wifi
)
{
_my_announce
->
publish
(
doc
.
c_str
());
}
if
(
_wifi
)
{
_my_announce
->
publish
(
doc
.
c_str
());
}
Serial
.
print
(
"-->"
);
Serial
.
print
(
"-->"
);
Serial
.
println
(
doc
);
Serial
.
println
(
doc
);
...
@@ -247,22 +259,31 @@ public:
...
@@ -247,22 +259,31 @@ public:
Serial
.
println
(
doc
);
Serial
.
println
(
doc
);
}
}
void
input_greeting
()
{
if
(
_wifi
)
{
if
(
!
_input
->
publish
(
_id
)
)
{
Serial
.
println
(
"Couldn't publish input greeting"
);
}
}
String
doc
=
String
(
"This is "
)
+
String
(
_id
)
+
String
(
"'s input channel. Hello!'"
);
if
(
_wifi
)
{
_my_input
->
publish
(
doc
.
c_str
());
}
Serial
.
print
(
"-->"
);
Serial
.
println
(
doc
);
}
void
setID
(
char
*
id
)
{
void
setID
(
char
*
id
)
{
_id
=
id
;
_id
=
id
;
}
}
};
};
class
SendCapabilities
:
public
Behaviour
{
/*
* Class that defines a behaviour that publishes a
* ButtonPressed message to the input topic of the
* MQQT broker
*/
WallVis
*
_node
;
public:
SendCapabilities
(
WallVis
*
node
,
String
name
=
"SendCapabilities"
)
:
Behaviour
(
name
),
_node
(
node
){
}
String
start
(
String
args
)
{
//This is where you do your stuff for a simple behaviour
_node
->
announce_capabilities
();
return
"SendCapabilities behaviour "
+
_name
;
}
};
/*
/*
* Button Behaviours depend on WallVis class so they must be included after
* Button Behaviours depend on WallVis class so they must be included after
* it has been defined.
* it has been defined.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment