20 #include <ESP8266WiFi.h>
21 #include <ESP8266WiFiAP.h>
27#include <WiFiClient.h>
35#ifndef BOARD_DEBUG_UART_BAUDRATE
36#define BOARD_DEBUG_UART_BAUDRATE 115200
42 #define PIN_I2C_SDA (12)
43 #define PIN_I2C_SCL (14)
46 #define PIN_I2C_SDA (-1)
47 #define PIN_I2C_SCL (-1)
50#define BOARD_ACCEL_MAG_I2C_ADDR (0x1F)
51#define BOARD_GYRO_I2C_ADDR (0x21)
56 #define DEBUG_OUTPUT_PIN 15
57 #define GPIO_MODE_OUTPUT OUTPUT
61 #define DEBUG_OUTPUT_PIN GPIO_NUM_14
69#if F_USE_WIRELESS_UART
70 const char *ssid =
"compass";
71 const char *password =
"northsouth";
72 #define WIFI_STREAMING_PORT 23
73 WiFiServer server(WIFI_STREAMING_PORT);
74 WiFiClient tcp_client;
81unsigned long last_loop_time;
82unsigned long last_print_time;
85#define MAX_LEN_OUT_BUF 180
86char output_str[MAX_LEN_OUT_BUF];
94 pinMode(DEBUG_OUTPUT_PIN, GPIO_MODE_OUTPUT);
96 Serial.begin(BOARD_DEBUG_UART_BAUDRATE);
99 Serial.println(
"Serial port configured.");
102#if F_USE_WIRELESS_UART
104 WiFi.softAP(ssid, password);
105 IPAddress myIP = WiFi.softAPIP();
106 Serial.print(
"My AP IP address: ");
107 Serial.println(myIP);
109 Serial.print(
"TCP server started. Connect to ");
111 Serial.println(
" on port 23.");
135#if F_USE_WIRELESS_UART && F_USE_WIRED_UART
138 Serial.println(
"trouble initting Output and Control system");
140#elif F_USE_WIRED_UART
143 Serial.println(
"trouble initting Output and Control system");
145#elif F_USE_WIRELESS_UART
148 Serial.println(
"trouble initting Output and Control system");
153 Serial.println(
"trouble initting Output and Control system");
159 SensorType::kMagnetometer) ) {
160 Serial.println(
"trouble installing Magnetometer");
163 SensorType::kAccelerometer) ) {
164 Serial.println(
"trouble installing Accelerometer");
167 SensorType::kThermometer) ) {
168 Serial.println(
"trouble installing Thermometer");
171 SensorType::kGyroscope) ) {
172 Serial.println(
"trouble installing Gyroscope");
174 Serial.println(
"Sensors connected");
176 sensor_fusion->
Begin(PIN_I2C_SDA, PIN_I2C_SCL);
178 { Serial.println(
"Fusion Engine Ready");
180 { Serial.printf(
"Fusion status: %d\n",(
int)sensor_fusion->
GetSystemStatus());
184 last_loop_time = millis();
185 last_print_time = millis();
201 const unsigned long kLoopIntervalMs = 1000 / LOOP_RATE_HZ;
202 const unsigned long kPrintIntervalMs = 1000;
204#if F_USE_WIRELESS_UART
206 tcp_client = server.available();
212 if ((millis() - last_loop_time) > kLoopIntervalMs) {
213 last_loop_time += kLoopIntervalMs;
234 digitalWrite(DEBUG_OUTPUT_PIN, i % 2);
242 if ((millis() - last_print_time) > kPrintIntervalMs) {
243 last_print_time += kPrintIntervalMs;
244 snprintf(output_str, MAX_LEN_OUT_BUF,
245 "%lu: Heading %03.0f, Pitch %+4.0f, Roll %+4.0f, Temp %3.0fC, TurnRate %+5.0f, B %3.0f uT, Inc %3.0f deg, Status %d",
257 Serial.println( output_str );
Board configuration file.
Build configuration file.
float GetRollDegrees(void)
bool InstallSensor(uint8_t sensor_i2c_addr, SensorType sensor_type)
Install Sensor in linked list The max length of the list is checked, and if there is room,...
float GetPitchDegrees(void)
float GetMagneticInclinationDeg(void)
void UpdateWiFiStream(void *tcp_client)
Update the TCP client pointer. Call when a new TCP connection is made, as reported by WiFiServer::ava...
float GetTurnRateDegPerS(void)
void ReadSensors(void)
Reads all sensors. Applies HAL remapping, removes invalid values, and stores data for later processin...
void Begin(int pin_i2c_sda=-1, int pin_i2c_scl=-1)
float GetTemperatureC(void)
bool InitializeInputOutputSubsystem(const Stream *serial_port=NULL, const void *tcp_client=NULL)
void RunFusion(void)
Apply fusion algorithm to sensor raw data. Sensor readings contained in global struct are calibrated ...
float GetMagneticBMag(void)
float GetHeadingDegrees(void)
int GetSystemStatus(void)
@ NORMAL
Operation is Nominal.