Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
EMM
meteorolog
Commits
b4ff0355
Commit
b4ff0355
authored
Jun 13, 2017
by
Nelso Jost
Browse files
DEV: refactor repl; ADD: wifi, software serial
parent
4fbbb322
Changes
8
Show whitespace changes
Inline
Side-by-side
esplogger/Makefile
View file @
b4ff0355
PORT
:=
PORT
:=
BAUD
:=
115200
BAUD
:=
115200
PIOBOARD
=
esp12e
PIOBOARD
=
nodemcuv2
PIOPROJ
=
firmware/esplogger
PIOPROJ
=
firmware/esplogger
PIODIR
=
.pio
PIODIR
=
.pio
...
@@ -9,17 +9,33 @@ PIODIR = .pio
...
@@ -9,17 +9,33 @@ PIODIR = .pio
all
:
firmware
all
:
firmware
install-pip3
:
wget https://bootstrap.pypa.io/get-pip.py
&&
\
sudo
python3 get-pip.py
&&
rm
get-pip.py
install-platformio
:
install-platformio
:
wget https://bootstrap.pypa.io/get-pip.py
&&
\
wget https://bootstrap.pypa.io/get-pip.py
&&
\
sudo
python get-pip.py
&&
rm
get-pip.py
sudo
python get-pip.py
&&
rm
get-pip.py
sudo
pip
install
platformio
sudo
pip
install
platformio
$(MAKE)
add-udev-rules
$(MAKE)
add-dialout
add-dialout
:
sudo
usermod
-a
-G
dialout
$$
USER
add-udevrules
:
wget https://raw.githubusercontent.com/platformio/platformio/develop/scripts/99-platformio-udev.rules
sudo cp
-v
99-platformio-udev.rules /etc/udev/rules.d
sudo
service udev restart
firmware
:
build upload monitor
firmware
:
build upload monitor
build
:
build
:
which platformio
||
$(MAKE)
install-platformio
@
echo
"
$$
PIO_BUILD"
| sh
@
echo
"
$$
PIO_BUILD"
| sh
upload
:
upload
:
which platformio
||
$(MAKE)
install-platformio
cd
$(PIODIR)
&&
platformio run
-t
upload
cd
$(PIODIR)
&&
platformio run
-t
upload
monitor
:
monitor
:
...
...
esplogger/firmware/esplogger/esplogger.ino
View file @
b4ff0355
...
@@ -4,12 +4,29 @@
...
@@ -4,12 +4,29 @@
* Purpose: Entry point for the Arduino Toolchain.
* Purpose: Entry point for the Arduino Toolchain.
*---------------------------------------------------------------------------*/
*---------------------------------------------------------------------------*/
#include <Arduino.h>
#include <Arduino.h>
#include <Ticker.h>
#include "repl.h"
#include "repl.h"
#include "repl_gpio.h"
#include "repl_gpio.h"
#include "repl_sdcard.h"
#include "repl_sdcard.h"
#include "wifi.h"
#include "wifi.h"
#include <SoftwareSerial.h>
#define PIN_LED 0 // D3
#define PIN_BUTTON 2 // D4
#define ARDUINO_TX 5 // D1 (soft RX)
#define ARDUINO_RX 4 // D2 (soft TX)
void
REPL_WIFISCAN
(
REPL
*
repl
);
void
REPL_WIFISCAN
(
REPL
*
repl
);
void
REPL_WIFISTATUS
(
REPL
*
repl
);
void
REPL_WIFICONNECT
(
REPL
*
repl
);
void
REPL_ARDUINO
(
REPL
*
repl
);
SoftwareSerial
arduinoSerial
(
ARDUINO_TX
,
ARDUINO_RX
);
// RX, TX
REPL_COMMAND
commands
[]
=
\
REPL_COMMAND
commands
[]
=
\
{
{
...
@@ -19,20 +36,50 @@ REPL_COMMAND commands[] =\
...
@@ -19,20 +36,50 @@ REPL_COMMAND commands[] =\
{
"wifiscan"
,
REPL_WIFISCAN
,
"wifiscan"
,
{
"wifiscan"
,
REPL_WIFISCAN
,
"wifiscan"
,
"List all availables SSID in range for connection."
},
"List all availables SSID in range for connection."
},
{
"wifistatus"
,
REPL_WIFISTATUS
,
"wifistatus"
,
"Print WiFi debug info (connection status)."
},
{
"wificonnect"
,
REPL_WIFICONNECT
,
"wificonnect <ssid> <password>"
,
"Connect to wifi network."
},
{
"arduino"
,
REPL_ARDUINO
,
"arduino <command>"
,
"Sendo command to arduino."
},
{
NULL
}
{
NULL
}
};
};
REPL
repl
(
commands
);
REPL
repl
(
commands
);
int
led_state
=
0
;
int
button_state
=
0
;
Ticker
timer_button
;
void
setup
()
void
setup
()
{
{
Serial
.
begin
(
9600
);
Serial
.
begin
(
9600
);
repl
.
run
();
timer_button
.
attach
(
0.1
,
toggle_led
);
arduinoSerial
.
begin
(
9600
);
}
}
void
loop
()
void
loop
()
{
{
repl
.
update
();
}
void
toggle_led
()
{
int
reading
=
digitalRead
(
PIN_BUTTON
);
if
(
button_state
!=
reading
)
{
button_state
=
reading
;
if
(
button_state
==
HIGH
)
{
led_state
=
!
led_state
;
pinMode
(
PIN_LED
,
OUTPUT
);
digitalWrite
(
PIN_LED
,
led_state
);
}
}
}
}
...
@@ -41,6 +88,17 @@ void REPL_WIFISCAN(REPL * repl)
...
@@ -41,6 +88,17 @@ void REPL_WIFISCAN(REPL * repl)
wifiscan
();
wifiscan
();
}
}
void
REPL_WIFISTATUS
(
REPL
*
repl
)
{
wifistatus
();
}
void
REPL_WIFICONNECT
(
REPL
*
repl
)
{
wificonnect
(
repl
->
get_arg
(
1
),
repl
->
get_arg
(
2
),
10
);
}
void
REPL_ARDUINO
(
REPL
*
repl
)
{
arduinoSerial
.
print
(
"baka"
);
}
esplogger/firmware/esplogger/repl.cpp
View file @
b4ff0355
...
@@ -15,12 +15,12 @@ REPL::REPL(REPL_COMMAND * command_map)
...
@@ -15,12 +15,12 @@ REPL::REPL(REPL_COMMAND * command_map)
}
}
void
REPL
::
run
(
void
)
void
REPL
::
update
(
void
)
{
{
char
c
;
char
c
;
while
(
1
)
{
if
(
!
Serial
.
available
())
{
yield
();
return
;
}
while
(
!
Serial
.
available
())
{
yield
();
}
c
=
Serial
.
read
();
c
=
Serial
.
read
();
if
(
c
==
8
)
if
(
c
==
8
)
...
@@ -35,6 +35,8 @@ void REPL::run(void)
...
@@ -35,6 +35,8 @@ void REPL::run(void)
else
if
(
c
==
']'
)
else
if
(
c
==
']'
)
this
->
_history_next
();
this
->
_history_next
();
else
if
(
c
==
32
&&
!
this
->
_command_buffer
.
length
())
return
;
else
else
{
{
this
->
_command_buffer
+=
c
;
this
->
_command_buffer
+=
c
;
...
@@ -47,35 +49,51 @@ void REPL::run(void)
...
@@ -47,35 +49,51 @@ void REPL::run(void)
this
->
_command_buffer
.
indexOf
(
"
\n
"
)
!=
-
1
)
this
->
_command_buffer
.
indexOf
(
"
\n
"
)
!=
-
1
)
{
{
this
->
_command_buffer
.
trim
();
this
->
_command_buffer
.
trim
();
if
(
this
->
_command_buffer
==
"help"
)
this
->
print_help
();
else
{
if
(
this
->
_command_buffer
!=
""
)
if
(
this
->
_command_buffer
!=
""
)
{
{
this
->
_execute_command
();
if
(
this
->
_command_buffer
==
"help"
)
this
->
print_help
();
else
this
->
_execute_command
();
this
->
_command_buffer
=
""
;
this
->
_command_buffer
=
""
;
}
}
else
{
this
->
_command_buffer
=
" "
;
}
}
if
(
c
!=
13
)
Serial
.
print
(
this
->
prompt
+
" "
);
if
(
c
!=
13
)
Serial
.
print
(
this
->
prompt
+
" "
);
}
}
Serial
.
flush
();
Serial
.
flush
();
}
}
}
void
REPL
::
_clear_line
(
void
)
void
REPL
::
_clear_line
(
void
)
{
{
Serial
.
print
(
"
\r
"
if
(
this
->
_command_buffer
.
length
())
" "
{
"
\r
"
);
this
->
_complete
();
return
;
}
Serial
.
print
(
"
\r
\r
"
);
Serial
.
print
(
"> "
);
Serial
.
print
(
"> "
);
this
->
_command_buffer
=
""
;
this
->
_command_buffer
=
""
;
}
}
void
REPL
::
_complete
(
void
)
{
String
partial_name
=
this
->
get_arg
(
0
);
REPL_COMMAND
*
rc
=
this
->
_fp_map
;
String
full_name
;
while
(
rc
->
name
!=
NULL
)
{
full_name
=
String
(
rc
->
name
);
if
(
full_name
.
startsWith
(
partial_name
))
{
Serial
.
print
(
"
\n\n
[HELP] "
+
String
(
rc
->
prototype
)
+
"
\n
"
+
this
->
prompt
+
" "
+
full_name
+
" "
);
this
->
_command_buffer
=
full_name
+
" "
;
}
rc
++
;
}
}
void
REPL
::
_backspace
(
void
)
void
REPL
::
_backspace
(
void
)
{
{
if
(
this
->
_command_buffer
.
length
()
!=
0
)
if
(
this
->
_command_buffer
.
length
()
!=
0
)
...
@@ -118,6 +136,7 @@ void REPL::_history_next(void)
...
@@ -118,6 +136,7 @@ void REPL::_history_next(void)
//this->log("history next" + String(this->_history_index));
//this->log("history next" + String(this->_history_index));
}
}
void
REPL
::
_history_save
(
void
)
void
REPL
::
_history_save
(
void
)
{
{
this
->
_history_index
=
0
;
this
->
_history_index
=
0
;
...
...
esplogger/firmware/esplogger/repl.h
View file @
b4ff0355
...
@@ -19,6 +19,7 @@ typedef struct
...
@@ -19,6 +19,7 @@ typedef struct
}
REPL_COMMAND
;
}
REPL_COMMAND
;
class
REPL
class
REPL
{
{
public:
public:
...
@@ -26,9 +27,9 @@ public:
...
@@ -26,9 +27,9 @@ public:
String
prompt
=
">"
;
String
prompt
=
">"
;
void
run
(
void
);
void
update
(
void
);
void
print_help
(
void
);
void
print_help
(
void
);
void
log
(
String
msg
,
bool
show_buffer
=
tru
e
);
void
log
(
String
msg
,
bool
show_buffer
=
fals
e
);
String
get_arg
(
int
index
);
String
get_arg
(
int
index
);
private:
private:
...
@@ -39,6 +40,7 @@ private:
...
@@ -39,6 +40,7 @@ private:
void
_backspace
(
void
);
void
_backspace
(
void
);
void
_clear_line
(
void
);
void
_clear_line
(
void
);
void
_complete
(
void
);
void
_history_previous
(
void
);
void
_history_previous
(
void
);
void
_history_next
(
void
);
void
_history_next
(
void
);
...
...
esplogger/firmware/esplogger/repl_gpio.cpp
View file @
b4ff0355
...
@@ -8,72 +8,134 @@
...
@@ -8,72 +8,134 @@
#include "blinker.h"
#include "blinker.h"
#define BUILTIN_LED 2
#define BUILTIN_LED 2
Blinker
blinker
(
BUILTIN_LED
);
Blinker
blinker
(
BUILTIN_LED
);
Ticker
alog_ticker
;
Ticker
log_ticker
;
typedef
struct
typedef
struct
{
{
char
pin_type
;
int
pin
;
int
pin
;
in
t
interval
;
floa
t
interval
;
REPL
*
repl
;
REPL
*
repl
;
}
ALOG_args
;
bool
show_buffer
;
}
LOG_args
;
void
REPL_DWRITE
(
REPL
*
repl
)
void
REPL_DWRITE
(
REPL
*
repl
)
{
{
String
arg_pin
=
repl
->
get_arg
(
1
);
char
pin_type
=
repl
->
get_arg
(
1
)[
0
];
int
pin
;
String
arg_value
=
repl
->
get_arg
(
2
);
String
arg_value
=
repl
->
get_arg
(
2
);
int
value
;
int
pin
=
arg_pin
.
toInt
();
if
(
pin_type
<
'0'
||
pin_type
>
'9'
)
int
value
=
!
arg_value
.
toInt
();
pin
=
repl
->
get_arg
(
1
).
substring
(
1
).
toInt
();
else
pin
=
repl
->
get_arg
(
1
).
toInt
();
analogWrite
(
pin
,
0
);
pinMode
(
pin
,
OUTPUT
);
if
(
arg_pin
==
"led"
)
pin
=
BUILTIN_LED
;
if
(
arg_value
==
"high"
)
value
=
0
;
if
(
arg_value
==
"high"
)
value
=
0
;
if
(
arg_value
==
"low"
)
value
=
1
;
else
if
(
arg_value
==
"low"
)
value
=
1
;
else
value
=
arg_value
.
toInt
();
pinMode
(
pin
,
OUTPUT
);
digitalWrite
(
pin
,
value
);
digitalWrite
(
pin
,
value
);
repl
->
log
(
"
\n
[INFO] Pin "
+
String
(
pin
)
+
" was set to "
+
repl
->
log
(
"
\n
[INFO] digitalWrite("
+
String
(
pin
)
+
", "
+
value
?
"HIGH"
:
"LOW"
);
String
(
value
?
"HIGH"
:
"LOW"
)
+
")"
);
}
void
REPL_AWRITE
(
REPL
*
repl
)
{
char
pin_type
=
repl
->
get_arg
(
1
)[
0
];
int
pin
;
String
arg_value
=
repl
->
get_arg
(
2
);
int
value
;
if
(
pin_type
<
'0'
||
pin_type
>
'9'
)
pin
=
repl
->
get_arg
(
1
).
substring
(
1
).
toInt
();
else
pin
=
repl
->
get_arg
(
1
).
toInt
();
pinMode
(
pin
,
OUTPUT
);
if
(
arg_value
==
"min"
)
value
=
0
;
else
if
(
arg_value
==
"max"
)
value
=
1023
;
else
value
=
arg_value
.
toInt
();
analogWrite
(
pin
,
value
);
repl
->
log
(
"
\n
[INFO] analogWrite("
+
String
(
pin
)
+
", "
+
String
(
value
)
+
")"
);
}
}
void
REPL_AREAD
(
REPL
*
repl
)
void
REPL_AREAD
(
REPL
*
repl
)
{
{
int
pin
=
repl
->
get_arg
(
1
).
toInt
();
int
pin
=
repl
->
get_arg
(
1
).
toInt
();
repl
->
log
(
"
\n
[INFO]
Read
analog
pin
"
+
String
(
pin
)
+
"
value:
"
+
repl
->
log
(
"
\n
[INFO] analog
Read(
"
+
String
(
pin
)
+
"
) -->
"
+
String
(
analogRead
(
pin
))
,
false
);
String
(
analogRead
(
pin
)));
}
}
void
alog_callback
(
ALOG_args
*
args
)
void
REPL_DREAD
(
REPL
*
repl
)
{
{
args
->
repl
->
log
(
"
\n
[LOG] a"
+
String
(
args
->
pin
)
+
":"
+
int
pin
=
repl
->
get_arg
(
1
).
toInt
();
String
(
analogRead
(
args
->
pin
)));
repl
->
log
(
"
\n
[INFO] digitalRead("
+
String
(
pin
)
+
") --> "
+
String
(
digitalRead
(
pin
)));
}
}
void
REPL_ALOG
(
REPL
*
repl
)
void
log_callback
(
LOG_args
*
args
)
{
{
ALOG_args
*
args
=
new
ALOG_args
;
String
value
;
int
pin
=
repl
->
get_arg
(
1
).
toInt
();
int
interval
=
repl
->
get_arg
(
2
).
toInt
();
if
(
args
->
pin_type
==
'd'
)
value
=
String
(
digitalRead
(
args
->
pin
));
else
value
=
String
(
analogRead
(
args
->
pin
));
args
->
repl
->
log
(
"
\n
[LOG] "
+
String
(
args
->
pin_type
)
+
String
(
args
->
pin
)
+
":"
+
value
,
args
->
show_buffer
);
args
->
show_buffer
=
true
;
}
void
REPL_LOG
(
REPL
*
repl
)
{
LOG_args
*
args
=
new
LOG_args
;
args
->
pin_type
=
repl
->
get_arg
(
1
)[
0
];
if
(
not
args
->
pin_type
==
'd'
&&
not
args
->
pin_type
==
'a'
)
{
repl
->
log
(
"
\n
[ERROR] Invalid pin format. Given
\"
"
+
repl
->
get_arg
(
1
)
+
"
\"
"
);
}
args
->
pin
=
repl
->
get_arg
(
1
).
substring
(
1
).
toInt
();
args
->
interval
=
repl
->
get_arg
(
2
).
toFloat
();
args
->
repl
=
repl
;
args
->
repl
=
repl
;
args
->
show_buffer
=
false
;
if
(
interval
==
0
)
if
(
args
->
interval
==
0
)
{
{
alog_ticker
.
detach
();
log_ticker
.
detach
();
repl
->
log
(
"
\n
[INFO] Deactivated datalog on analog pin "
+
repl
->
log
(
"
\n
[INFO] Deactivated log of pin "
+
repl
->
get_arg
(
1
)
+
"."
);
String
(
pin
)
+
"."
);
}
}
else
else
{
{
alog_callback
(
args
);
log_ticker
.
attach
(
args
->
interval
,
log_callback
,
args
);
alog_ticker
.
attach
(
interval
,
alog_callback
,
args
);
repl
->
log
(
"
\n
[INFO] Activated log of pin "
+
repl
->
get_arg
(
1
)
+
args
->
repl
->
log
(
"
\n
[INFO] Activated datalog on analog pin "
+
" with "
+
String
(
args
->
interval
)
+
" s interval."
);
String
(
pin
)
+
" with "
+
String
(
interval
)
log_callback
(
args
);
+
" s interval."
);
}
}
}
}
...
@@ -85,12 +147,12 @@ void REPL_BLINK(REPL * repl)
...
@@ -85,12 +147,12 @@ void REPL_BLINK(REPL * repl)
if
(
interval
==
0
)
if
(
interval
==
0
)
{
{
blinker
.
deactivate
();
blinker
.
deactivate
();
repl
->
log
(
"
\n
[INFO] Deactivated blink builtin led (pin 2)."
);
repl
->
log
(
"
\n
[INFO] Deactivated blink
on
builtin led (pin 2)."
);
}
}
else
else
{
{
blinker
.
activate
(
interval
);
blinker
.
activate
(
interval
);
repl
->
log
(
"
\n
[INFO] Activated blink builtin led (pin 2) with "
+
repl
->
log
(
"
\n
[INFO] Activated blink
on
builtin led (pin 2) with "
+
String
(
interval
)
+
" s interval."
);
String
(
interval
)
+
" s interval."
);
}
}
}
}
...
...
esplogger/firmware/esplogger/repl_gpio.h
View file @
b4ff0355
...
@@ -6,33 +6,45 @@
...
@@ -6,33 +6,45 @@
#ifndef REPL_GPIO_H
#ifndef REPL_GPIO_H
#define REPL_GPIO_H
#define REPL_GPIO_H
#define CMD_REPL_BLINK {\
"blink", REPL_BLINK, "blink <interval>", \
"Blink builtin led (pin 2) with given <interval> in seconds (int|float). " \
"Use \"blink 0\" to stop it."}
#define CMD_REPL_DWRITE {\
#define CMD_REPL_DWRITE {\
"dwrite", REPL_DWRITE, "dwrite <pin> <value>",\
"dwrite", REPL_DWRITE, "dwrite <pin> <value>",\
"Digital write <value> (number|high|low) on <pin>. "}
"Perform pinMode(pin, OUTPUT) and digitalWrite(pin, value)."}
#define CMD_REPL_AWRITE {\
"awrite", REPL_AWRITE, "awrite <pin> <value>",\
"Perform analogWrite(pin, value) with 0 <= PWM value <= 255 (duty cycle)."}
#define CMD_REPL_AREAD {\
#define CMD_REPL_AREAD {\
"aread", REPL_AREAD, "aread <pin>", \
"aread", REPL_AREAD, "aread <pin>", \
"
Read analogic pin and print out the value.
"}
"
Perform analogRead(pin)
"}
#define CMD_REPL_
ALOG
{\
#define CMD_REPL_
DREAD
{\
"
alog
", REPL_
ALOG, "alog <pin> <interval
>", \
"
dread
", REPL_
DREAD, "dread <pin
>", \
"
Start datalog on analogic pin with given interval.
"}
"
Perform digitalRead(pin)
"}
#define CMD_REPL_LOG {\
"log", REPL_LOG, "log <pin> <interval>", \
"Start logging a pin reading with given interval (in seconds). " \
"Pin must be aX (analog) or dX (digital) where X is an integer."}