Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ICBM
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
detectors
DSSC
ICBM
Commits
979a275c
Commit
979a275c
authored
1 year ago
by
Cyril Danilevski
Browse files
Options
Downloads
Patches
Plain Diff
WIP: poll snmp over rest
parent
365a0f0a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2
Initial MPOD feature
Pipeline
#131062
passed
1 year ago
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
icbm.ino
+0
-2
0 additions, 2 deletions
icbm.ino
mpod.cpp
+16
-0
16 additions, 0 deletions
mpod.cpp
mpod.hpp
+1
-0
1 addition, 0 deletions
mpod.hpp
rest.cpp
+17
-5
17 additions, 5 deletions
rest.cpp
rest.hpp
+1
-0
1 addition, 0 deletions
rest.hpp
with
35 additions
and
7 deletions
icbm.ino
+
0
−
2
View file @
979a275c
...
@@ -12,9 +12,7 @@ void setup() {
...
@@ -12,9 +12,7 @@ void setup() {
initializeNetwork
();
initializeNetwork
();
initializeRoutes
();
initializeRoutes
();
Serial
.
println
(
"Started REST server"
);
initializeSNMP
();
initializeSNMP
();
Serial
.
println
(
"Started SNMP server"
);
start
=
millis
();
start
=
millis
();
}
}
...
...
This diff is collapsed.
Click to expand it.
mpod.cpp
+
16
−
0
View file @
979a275c
...
@@ -146,6 +146,21 @@ float MPOD::getFloatFromVarBind(const VarBind *varbind) {
...
@@ -146,6 +146,21 @@ float MPOD::getFloatFromVarBind(const VarBind *varbind) {
return
static_cast
<
OpaqueFloatBER
*>
(
static_cast
<
OpaqueBER
*>
(
varbind
->
getValue
())
->
getBER
())
->
getValue
();
return
static_cast
<
OpaqueFloatBER
*>
(
static_cast
<
OpaqueBER
*>
(
varbind
->
getValue
())
->
getBER
())
->
getValue
();
}
}
String
MPOD
::
toJSON
()
{
String
json
=
"
\"
status
\"
:{
\n
"
;
json
+=
"
\"
is_on
\"
:"
+
String
(
isOn
())
+
","
;
json
+=
"
\"
is_up
\"
:"
+
String
(
isUp
())
+
","
;
json
+=
"
\"
is_down
\"
:"
+
String
(
isDown
())
+
","
;
json
+=
"
\"
sense_voltage
\"
:"
+
String
(
getMeasurementSenseVoltage
())
+
","
;
json
+=
"
\"
set_voltage
\"
:"
+
String
(
getVoltage
())
+
","
;
json
+=
"
\"
sense_current
\"
:"
+
String
(
getMeasurementCurrent
())
+
","
;
json
+=
"
\"
set_current
\"
:"
+
String
(
getCurrent
())
+
","
;
json
+=
"
\"
voltage_rise_rate
\"
:"
+
String
(
getVoltageRiseRate
());
json
+=
"}"
;
return
json
;
}
WiFiUDP
udp
;
WiFiUDP
udp
;
SNMP
::
Manager
snmp
;
SNMP
::
Manager
snmp
;
...
@@ -183,4 +198,5 @@ void onMessage(const SNMP::Message *message, const IPAddress remote, const uint1
...
@@ -183,4 +198,5 @@ void onMessage(const SNMP::Message *message, const IPAddress remote, const uint1
void
initializeSNMP
()
{
void
initializeSNMP
()
{
snmp
.
begin
(
&
udp
);
snmp
.
begin
(
&
udp
);
snmp
.
onMessage
(
onMessage
);
snmp
.
onMessage
(
onMessage
);
Serial
.
println
(
"SNMP Server Started"
);
}
}
This diff is collapsed.
Click to expand it.
mpod.hpp
+
1
−
0
View file @
979a275c
...
@@ -62,6 +62,7 @@ class MPOD {
...
@@ -62,6 +62,7 @@ class MPOD {
float
getVoltage
()
const
;
float
getVoltage
()
const
;
float
getCurrent
()
const
;
float
getCurrent
()
const
;
float
getVoltageRiseRate
()
const
;
float
getVoltageRiseRate
()
const
;
String
toJSON
();
private
:
private
:
unsigned
int
getIntegerFromVarBind
(
const
VarBind
*
);
unsigned
int
getIntegerFromVarBind
(
const
VarBind
*
);
...
...
This diff is collapsed.
Click to expand it.
rest.cpp
+
17
−
5
View file @
979a275c
...
@@ -17,6 +17,7 @@ void initializeRoutes() {
...
@@ -17,6 +17,7 @@ void initializeRoutes() {
restServer
.
on
(
"/restart"
,
restart
);
restServer
.
on
(
"/restart"
,
restart
);
restServer
.
onNotFound
(
notFound
);
restServer
.
onNotFound
(
notFound
);
restServer
.
on
(
"/send"
,
sendSNMP
);
restServer
.
on
(
"/send"
,
sendSNMP
);
restServer
.
on
(
"/poll"
,
pollMPODChannel
);
restServer
.
begin
();
restServer
.
begin
();
Serial
.
println
(
"REST Server Started"
);
Serial
.
println
(
"REST Server Started"
);
...
@@ -102,18 +103,29 @@ void sendSNMP() {
...
@@ -102,18 +103,29 @@ void sendSNMP() {
}
}
}
}
auto
ip
_a
ddr
=
IPAddress
(
10
,
42
,
0
,
1
);
auto
ip
A
ddr
=
IPAddress
(
10
,
42
,
0
,
1
);
if
(
output
!=
NONE
)
{
if
(
output
!=
NONE
)
{
SNMP
::
Message
*
snmp_msg
=
mpod
.
output
(
output
);
SNMP
::
Message
*
snmp_msg
=
mpod
.
output
(
output
);
snmp
.
send
(
snmp_msg
,
ip
_a
ddr
,
SNMP
::
PORT
::
SNMP
);
snmp
.
send
(
snmp_msg
,
ip
A
ddr
,
SNMP
::
PORT
::
SNMP
);
delete
snmp_msg
;
delete
snmp_msg
;
success
=
true
;
success
=
true
;
}
}
String
http_msg
=
"{
\n
"
;
String
http_msg
=
"{
\n
"
;
http_msg
+=
"
\"
target
\"
:
\"
"
+
String
(
ip_addr
)
+
"
\"
,"
;
http_msg
+=
"
\"
target
\"
:
\"
"
+
ipAddr
.
toString
()
+
"
\"
,"
;
http_msg
+=
"
\"
arguments
\"
:{
\"
output
\"
:
\"
"
+
String
(
output
)
+
"
\"
},
\n
"
;
http_msg
+=
"
\"
arguments
\"
:{
\"
output
\"
:"
+
String
(
output
)
+
"},
\n
"
;
http_msg
+=
"
\"
success
\"
:
\"
"
+
String
(
success
)
+
"
\"
"
;
http_msg
+=
"
\"
success
\"
:"
+
String
(
success
);
http_msg
+=
"
\n
}"
;
restServer
.
send
(
200
,
"text/json"
,
http_msg
);
}
void
pollMPODChannel
()
{
auto
ret
=
mpod
.
toJSON
();
String
http_msg
=
"{
\n
"
;
http_msg
+=
ret
;
http_msg
+=
"
\"
success
\"
: 1"
;
http_msg
+=
"
\n
}"
;
http_msg
+=
"
\n
}"
;
restServer
.
send
(
200
,
"text/json"
,
http_msg
);
restServer
.
send
(
200
,
"text/json"
,
http_msg
);
...
...
This diff is collapsed.
Click to expand it.
rest.hpp
+
1
−
0
View file @
979a275c
...
@@ -9,3 +9,4 @@ void identify(); // /idn
...
@@ -9,3 +9,4 @@ void identify(); // /idn
void
notFound
();
// 404
void
notFound
();
// 404
void
restart
();
// /restart
void
restart
();
// /restart
void
sendSNMP
();
// /send?output=on
void
sendSNMP
();
// /send?output=on
void
pollMPODChannel
();
//mock the hardcoded mpod channel 0
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