Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
dcdb
dcdb
Commits
f97e003d
Commit
f97e003d
authored
Nov 03, 2018
by
lu43jih
Browse files
spreading the messages over time
parent
ff30abeb
Changes
4
Show whitespace changes
Inline
Side-by-side
.gitignore
0 → 100644
View file @
f97e003d
# eclise files
.cproject
.project
branchtest_deleteme.txt
deleted
100644 → 0
View file @
ff30abeb
src/MQTTPusher.cpp
View file @
f97e003d
...
...
@@ -72,8 +72,8 @@ void MQTTPusher::push() {
}
//collect sensor-data
reading_t
*
reads
=
new
reading_t
[
1024
];
std
::
size_t
totalCount
=
0
;
reading_t
*
reads
=
new
reading_t
[
SensorBase
::
QUEUE_MAXLIMIT
];
std
::
size_t
totalCount
=
0
;
//number of messages
while
(
_keepRunning
||
totalCount
)
{
if
(
_doHalt
)
{
_halted
=
true
;
...
...
@@ -82,6 +82,7 @@ void MQTTPusher::push() {
}
_halted
=
false
;
totalCount
=
0
;
unsigned
int
maxNumberOfMessages
=
100
;
for
(
auto
&
p
:
_plugins
)
{
if
(
_doHalt
)
{
//for faster response
...
...
@@ -90,7 +91,11 @@ void MQTTPusher::push() {
for
(
auto
g
:
p
.
configurator
->
getSensorGroups
())
{
for
(
auto
s
:
g
->
getSensors
())
{
if
(
s
->
getSizeOfReadingQueue
()
>=
g
->
getMinValues
())
{
if
(
totalCount
<
maxNumberOfMessages
){
sendReadings
(
s
,
reads
,
totalCount
);
}
else
{
break
;
//ultimately we will go to sleep 1 second
}
}
}
}
...
...
@@ -117,8 +122,9 @@ void MQTTPusher::sendReadings(SensorBase* s, reading_t* reads, std::size_t& tota
if
(
_connected
)
{
//get all sensor values out of its queue
std
::
size_t
count
=
s
->
popReadingQueue
(
reads
,
1024
);
totalCount
+=
count
;
std
::
size_t
count
=
s
->
popReadingQueue
(
reads
,
SensorBase
::
QUEUE_MAXLIMIT
);
//totalCount+= count;
totalCount
+=
1
;
#ifdef DEBUG
LOGM
(
debug
)
<<
"Sending "
<<
count
<<
" values from "
<<
s
->
getName
();
#endif
...
...
@@ -135,7 +141,8 @@ void MQTTPusher::sendReadings(SensorBase* s, reading_t* reads, std::size_t& tota
LOGM
(
error
)
<<
"Could not send message! Trying again later"
;
_connected
=
false
;
s
->
pushReadingQueue
(
reads
,
count
);
totalCount
-=
count
;
//totalCount -= count;
totalCount
-=
1
;
sleep
(
5
);
}
}
...
...
src/includes/SensorBase.h
View file @
f97e003d
...
...
@@ -19,6 +19,8 @@ typedef struct {
class
SensorBase
{
public:
static
const
size_t
QUEUE_MAXLIMIT
=
1024
;
SensorBase
(
const
std
::
string
&
name
)
:
_name
(
name
),
_mqtt
(
""
),
...
...
@@ -69,7 +71,7 @@ public:
}
}
if
(
!
_readingQueue
)
{
_readingQueue
.
reset
(
new
boost
::
lockfree
::
spsc_queue
<
reading_t
>
(
1024
));
_readingQueue
.
reset
(
new
boost
::
lockfree
::
spsc_queue
<
reading_t
>
(
QUEUE_MAXLIMIT
));
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment