esplogger.ino 2.09 KB
Newer Older
1
2
3
4
5
/*-----------------------------------------------------------------------------
 *  Author: Nelso G. Jost (nelsojost@gmail.com)
 *  License: GPLv2
 *  Purpose: Entry point for the Arduino Toolchain.
 *---------------------------------------------------------------------------*/
6
#include <Arduino.h>
7
#include <Ticker.h>
8
#include "repl.h"
9
10
#include "repl_gpio.h"
#include "repl_sdcard.h"
11
#include "wifi.h"
12

13
14
15
16
17
18
19
20
21
#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)


22
void REPL_WIFISCAN(REPL * repl);
23
24
25
26
27
28
29
void REPL_WIFISTATUS(REPL * repl);
void REPL_WIFICONNECT(REPL * repl);
void REPL_ARDUINO(REPL * repl);


SoftwareSerial arduinoSerial(ARDUINO_TX, ARDUINO_RX);  // RX, TX

30
31
32

REPL_COMMAND commands[] =\
{
33
34
35
36
37
38
    ALLCMD_REPL_GPIO,
    ALLCMD_REPL_SDCARD,

    {"wifiscan", REPL_WIFISCAN, "wifiscan",
     "List all availables SSID in range for connection."},

39
40
41
42
43
44
45
46
47
    {"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."},

48
    {NULL}
49
50
};
REPL repl(commands);
51

52
53
54
55
int led_state = 0;
int button_state = 0;

Ticker  timer_button;
56
57
58

void setup()
{
59
    Serial.begin(9600);
60
61
    timer_button.attach(0.1, toggle_led);
    arduinoSerial.begin(9600);
62
63
64
65
}

void loop()
{
66
67
68
    repl.update();
}

69

70
71
72
73
74
75
76
77
78
79
80
81
82
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);
        }
    }
83
84
85
}


86
void REPL_WIFISCAN(REPL * repl)
87
88
89
90
{
    wifiscan();
}

91
92
93
94
void REPL_WIFISTATUS(REPL * repl)
{
    wifistatus();
}
95

96
97
98
99
void REPL_WIFICONNECT(REPL * repl)
{
    wificonnect(repl->get_arg(1), repl->get_arg(2), 10);
}
100

101
102
103
104
void REPL_ARDUINO(REPL * repl)
{
    arduinoSerial.print("baka");
}