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
365a0f0a
Commit
365a0f0a
authored
1 year ago
by
Cyril Danilevski
Browse files
Options
Downloads
Patches
Plain Diff
Toggle an output from rest to snmp
parent
070fbb4e
No related branches found
No related tags found
1 merge request
!2
Initial MPOD feature
Pipeline
#130993
passed
1 year ago
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.md
+18
-0
18 additions, 0 deletions
README.md
icbm.ino
+4
-23
4 additions, 23 deletions
icbm.ino
rest.cpp
+41
-1
41 additions, 1 deletion
rest.cpp
rest.hpp
+5
-4
5 additions, 4 deletions
rest.hpp
with
68 additions
and
28 deletions
README.md
+
18
−
0
View file @
365a0f0a
...
...
@@ -4,6 +4,24 @@ ESP32 firmware for the IMC, based on Arduino and the `ESP32-Ethernet-Kit_A_V1.2`
This project depends on
[
`Arduino_SNMP`
](
https://github.com/patricklaf/SNMP
)
.
## Usage
The IMC is meant to be used over network using HTTP get and post.
### Routes
All routes return JSON.
Available routes are:
-
`/idn`
: provides information about firmware and hardware version, and uptime.
It can be queried as a heartbeat, seeing the uptime increasing.
### Serial Interface
The serial interface is available through the micro-usb port.
It prints basic networking information, as well as a heartbeat (
`-`
if ethernet is disconnected, else
`.`
).
## Development
### Quirks
...
...
This diff is collapsed.
Click to expand it.
icbm.ino
+
4
−
23
View file @
365a0f0a
...
...
@@ -11,11 +11,6 @@ void setup() {
Serial
.
begin
(
115200
);
initializeNetwork
();
while
(
!
eth_connected
)
{
Serial
.
print
(
"-"
);
delay
(
100
);
}
initializeRoutes
();
Serial
.
println
(
"Started REST server"
);
initializeSNMP
();
...
...
@@ -32,29 +27,15 @@ enum {
};
void
serial_loop
()
{
if
(
Serial
.
available
())
{
uint8_t
output
=
NONE
;
// Read command from serial
String
string
=
Serial
.
readString
();
string
.
toLowerCase
();
// Only two commands
if
(
string
==
"on"
)
{
output
=
ON
;
}
else
if
(
string
==
"off"
)
{
output
=
OFF
;
}
Serial
.
print
(
output
);
if
(
millis
()
-
start
>=
1000
)
{
start
=
millis
();
Serial
.
print
(
eth_connected
?
"."
:
"-"
);
}
}
void
loop
()
{
// Manager loop function must be called to process incoming messages
snmp
.
loop
();
restServer
.
handleClient
();
serial_loop
();
if
(
millis
()
-
start
>=
1000
)
{
start
=
millis
();
Serial
.
print
(
"."
);
}
}
This diff is collapsed.
Click to expand it.
rest.cpp
+
41
−
1
View file @
365a0f0a
#include
"rest.hpp"
#include
"mpod.hpp"
#include
<ETH.h>
#ifndef ICBM_GIT_VERSION
#define ICBM_GIT_VERSION "DEVEL"
// set via -DICBM_GIT_VERSION
#define ICBM_GIT_VERSION "DEVEL"
#endif
#ifndef ICBM_GIT_TIMESTAMP
...
...
@@ -15,6 +16,7 @@ void initializeRoutes() {
restServer
.
on
(
"/idn"
,
identify
);
restServer
.
on
(
"/restart"
,
restart
);
restServer
.
onNotFound
(
notFound
);
restServer
.
on
(
"/send"
,
sendSNMP
);
restServer
.
begin
();
Serial
.
println
(
"REST Server Started"
);
...
...
@@ -78,3 +80,41 @@ void restart() {
restServer
.
send
(
200
);
ESP
.
restart
();
}
enum
{
ON
,
OFF
,
NONE
,
};
void
sendSNMP
()
{
uint8_t
output
=
NONE
;
bool
success
=
false
;
for
(
uint8_t
i
=
0
;
i
<
restServer
.
args
();
i
++
)
{
if
(
restServer
.
argName
(
i
)
==
"output"
)
{
if
(
restServer
.
arg
(
i
)
==
"on"
)
{
output
=
ON
;
}
else
if
(
restServer
.
arg
(
i
)
==
"off"
)
{
output
=
OFF
;
}
}
}
auto
ip_addr
=
IPAddress
(
10
,
42
,
0
,
1
);
if
(
output
!=
NONE
)
{
SNMP
::
Message
*
snmp_msg
=
mpod
.
output
(
output
);
snmp
.
send
(
snmp_msg
,
ip_addr
,
SNMP
::
PORT
::
SNMP
);
delete
snmp_msg
;
success
=
true
;
}
String
http_msg
=
"{
\n
"
;
http_msg
+=
"
\"
target
\"
:
\"
"
+
String
(
ip_addr
)
+
"
\"
,"
;
http_msg
+=
"
\"
arguments
\"
:{
\"
output
\"
:
\"
"
+
String
(
output
)
+
"
\"
},
\n
"
;
http_msg
+=
"
\"
success
\"
:
\"
"
+
String
(
success
)
+
"
\"
"
;
http_msg
+=
"
\n
}"
;
restServer
.
send
(
200
,
"text/json"
,
http_msg
);
}
This diff is collapsed.
Click to expand it.
rest.hpp
+
5
−
4
View file @
365a0f0a
...
...
@@ -4,7 +4,8 @@
extern
WebServer
restServer
;
void
initializeRoutes
();
void
identify
();
void
notFound
();
void
list
();
void
restart
();
void
identify
();
// /idn
void
notFound
();
// 404
void
restart
();
// /restart
void
sendSNMP
();
// /send?output=on
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