-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathslap_dash_client.ino
More file actions
84 lines (73 loc) · 2.33 KB
/
Copy pathslap_dash_client.ino
File metadata and controls
84 lines (73 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <Wire.h>
#include <SoftwareSerial.h>
#include <ESP8266.h>
#include "rgb_led.h"
#include "accel_sensor.h"
#define ARD_RX_ESP_TX (8)
#define ARD_TX_ESP_RX (10)
#define ESP_RST (4)
#define TAP_INT (2)
/* Globals */
SoftwareSerial softser(ARD_RX_ESP_TX, ARD_TX_ESP_RX);
ESP8266 wifi(&softser, &Serial, ESP_RST);
//ESP8266 wifi(&softser, NULL, ESP_RST);
char WiFiBuffer[256];
#define ESP_SSID "" // Your network name here
#define ESP_PASS "" // Your network password here
#define HOST "www.neil-lakin.com" // Host to contact
#define GET_PAGE "/test_api" // test GET request
#define POST_PAGE "/test_post" // for testing POST requests
#define PORT 80 // 80 = HTTP default port
void setup() {
// put your setup code here, to run once:
initRGB();
pinMode(TAP_INT, INPUT);
initAccelSensor();
toggleClick(true);
wifi.setBootMarker(F("ready"));
softser.begin(9600); // Soft serial connection to ESP8266
Serial.begin(57600); while(!Serial); // UART serial debug
// Test if module is ready
Serial.print(F("Hard reset..."));
if(!wifi.hardReset()) {
Serial.println(F("no response from module."));
for(;;);
}
Serial.println(F("OK."));
Serial.print(F("Soft reset..."));
if(!wifi.softReset()) {
Serial.println(F("no response from module."));
for(;;);
}
Serial.print(F("Connecting to WiFi..."));
if(wifi.connectToAP(F(ESP_SSID), F(ESP_PASS))) {
// IP addr check isn't part of library yet, but
// we can manually request and place in a string.
Serial.print(F("OK\nChecking IP addr..."));
wifi.println(F("AT+CIFSR"));
if(wifi.readLine(WiFiBuffer, sizeof(WiFiBuffer))) {
Serial.println(WiFiBuffer);
wifi.find(); // Discard the 'OK' that follows
Serial.print(F("Connecting to host..."));
if(wifi.connectTCP(F(HOST), PORT)) {
Serial.println(F("Connected to server."));
} else {
Serial.println(F("Failed to connect to server."));
}
} else {
Serial.println(F("Failed to get IP..."));
}
} else {
Serial.println(F("Failed to connect to AP"));
}
}
void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(TAP_INT)) {
Serial.print("tapped");
wifi.postURL(F(POST_PAGE));
wifi.find(F("}"));
clearInterrupt();
delay(2);
}
}