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
e8a3fde1
Commit
e8a3fde1
authored
4 years ago
by
emorgan
Browse files
Options
Downloads
Patches
Plain Diff
WIP adding deep sleep
parent
55c394da
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/NameDictionary.h
+2
-1
2 additions, 1 deletion
src/NameDictionary.h
src/ServoBehaviours.h
+2
-2
2 additions, 2 deletions
src/ServoBehaviours.h
src/VizBlocks.cpp
+54
-36
54 additions, 36 deletions
src/VizBlocks.cpp
src/VizBlocks.h
+7
-0
7 additions, 0 deletions
src/VizBlocks.h
with
65 additions
and
39 deletions
src/NameDictionary.h
+
2
−
1
View file @
e8a3fde1
...
...
@@ -40,7 +40,7 @@ class NameDictionary
{
"da516d"
,
"aya"
},
{
"c2a597"
,
"bea"
},
{
"da5331"
,
"bev"
},
{
"8e07b"
,
"bob"
},
{
"8e07b"
,
"bob"
},
{
"c318a1"
,
"bud"
},
{
"da5a56"
,
"deb"
},
{
"da4a70"
,
"cal"
},
...
...
@@ -56,6 +56,7 @@ class NameDictionary
{
"31054b"
,
"kev"
},
{
"30ce48"
,
"sam"
},
{
"30db8b"
,
"tim"
},
{
"8e1ac"
,
"eve"
},
};
int
_arraySize
;
...
...
This diff is collapsed.
Click to expand it.
src/ServoBehaviours.h
+
2
−
2
View file @
e8a3fde1
...
...
@@ -38,8 +38,8 @@ class ServoWiggle : public Behaviour
int
_wiggle_factor
=
5
;
public:
ServoWiggle
(
Servo
servo
,
String
name
=
"Wiggle"
,
int
slowness
=
3
)
char
*
args
()
ServoWiggle
(
Servo
servo
,
String
name
=
"Wiggle"
,
int
slowness
=
3
)
;
char
*
args
()
;
String
start
(
String
args
);
void
update
();
...
...
This diff is collapsed.
Click to expand it.
src/VizBlocks.cpp
+
54
−
36
View file @
e8a3fde1
...
...
@@ -49,6 +49,19 @@ void VizBlock::MQTT_connect()
}
Serial
.
print
(
"Connecting to MQTT... "
);
// Setup MQTT
_client
=
new
WiFiClient
();
_mqtt
=
new
Adafruit_MQTT_Client
(
_client
,
_server
,
_port
,
""
/* mqttt username */
,
""
/* mqtt pass*/
);
_device_subscription
=
new
Adafruit_MQTT_Subscribe
(
_mqtt
,
_id
);
_announce
=
new
Adafruit_MQTT_Publish
(
_mqtt
,
"announce"
);
_my_announce_channel
=
String
(
"announce/"
)
+
String
(
_id
);
_my_announce
=
new
Adafruit_MQTT_Publish
(
_mqtt
,
_my_announce_channel
.
c_str
());
// Setup MQTT subscription for this device
_mqtt
->
subscribe
(
_device_subscription
);
// This *would* setup a callback, but we're not doing this right now...
//_device_subscription->setCallback(test_callback);
uint8_t
retries
=
3
;
...
...
@@ -71,6 +84,46 @@ void VizBlock::MQTT_connect()
Serial
.
println
(
"MQTT Connected!"
);
};
void
VizBlock
::
wifi_connect
()
{
WiFi
.
mode
(
WIFI_STA
);
WiFi
.
setSleepMode
(
WIFI_NONE_SLEEP
);
// Connect to WiFi access point.
Serial
.
println
();
Serial
.
print
(
"Connecting to "
);
Serial
.
println
(
_ssid
);
WiFi
.
begin
(
_ssid
,
_wifi_pass
);
_wifi_timeout_initialMillis
=
millis
();
_wifi_timeout
=
30000
;
Serial
.
println
(
"Checking for WiFi..."
);
while
(
WiFi
.
status
()
!=
WL_CONNECTED
)
{
unsigned
long
currentMillis
=
millis
();
if
(
currentMillis
-
_wifi_timeout_initialMillis
<
_wifi_timeout
)
{
Serial
.
print
(
"."
);
delay
(
500
);
}
else
{
Serial
.
println
(
"No WiFi found. Going to sleep for a bit..."
);
ESP
.
deepSleep
(
10e6
);
}
}
Serial
.
println
();
Serial
.
println
(
"WiFi connected"
);
Serial
.
println
(
"IP address: "
);
Serial
.
print
(
WiFi
.
localIP
());
// Done Wifi
};
void
VizBlock
::
run
()
{
int
loop_start_time
=
millis
();
...
...
@@ -121,42 +174,7 @@ void VizBlock::init()
if
(
_wifi
)
{
WiFi
.
mode
(
WIFI_STA
);
WiFi
.
setSleepMode
(
WIFI_NONE_SLEEP
);
// Connect to WiFi access point.
Serial
.
println
();
Serial
.
print
(
"Connecting to "
);
Serial
.
println
(
_ssid
);
WiFi
.
begin
(
_ssid
,
_wifi_pass
);
while
(
WiFi
.
status
()
!=
WL_CONNECTED
)
{
delay
(
500
);
Serial
.
print
(
"."
);
}
Serial
.
println
();
Serial
.
println
(
"WiFi connected"
);
Serial
.
println
(
"IP address: "
);
Serial
.
println
(
WiFi
.
localIP
());
// Done Wifi
// Setup MQTT
_client
=
new
WiFiClient
();
_mqtt
=
new
Adafruit_MQTT_Client
(
_client
,
_server
,
_port
,
""
/* mqttt username */
,
""
/* mqtt pass*/
);
_device_subscription
=
new
Adafruit_MQTT_Subscribe
(
_mqtt
,
_id
);
_announce
=
new
Adafruit_MQTT_Publish
(
_mqtt
,
"announce"
);
_my_announce_channel
=
String
(
"announce/"
)
+
String
(
_id
);
_my_announce
=
new
Adafruit_MQTT_Publish
(
_mqtt
,
_my_announce_channel
.
c_str
());
// Setup MQTT subscription for this device
_mqtt
->
subscribe
(
_device_subscription
);
// This *would* setup a callback, but we're not doing this right now...
//_device_subscription->setCallback(test_callback);
wifi_connect
();
MQTT_connect
();
}
...
...
This diff is collapsed.
Click to expand it.
src/VizBlocks.h
+
7
−
0
View file @
e8a3fde1
...
...
@@ -38,6 +38,8 @@ class VizBlock
Behaviour
*
_background
[
NUM_BACKGROUND_BEHAVIOURS
];
int
_loop_time
=
5
;
unsigned
long
_wifi_timeout
;
// How long to wait for wifi until we go into deep sleep
unsigned
long
_wifi_timeout_initialMillis
;
Adafruit_MQTT_Client
*
_mqtt
;
Adafruit_MQTT_Subscribe
*
_device_subscription
;
...
...
@@ -108,6 +110,11 @@ public:
*/
void
MQTT_connect
();
/**
* Function to connect and reconnect as necessary to the WIFI.
*/
void
wifi_connect
();
/**
Generates an array json formatted string containing information about
each of the behaviours the block can perform.
...
...
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