Hi,
I want to read BMP280 sensor data wirelessly using the ESP8266 as an access point.
My code compiles but when I go to upload I get the error:
Arduino: 1.8.4 (Mac OS X), Board: "Adafruit HUZZAH ESP8266, 80 MHz, 4M (1M SPIFFS), v2 Prebuilt (MSS=536), Disabled, None, 115200"
Archiving built core (caching) in: /var/folders/nx/c95f50fx2z18gmv1msbs5sch0000gn/T/arduino_cache_670987/core/core_esp8266_esp8266_huzzah_CpuFrequency_80,FlashSize_4M1M,LwIPVariant_v2mss536,Debug_Disabled,DebugLevel_None____,UploadSpeed_115200_90070322a63f92d8b02810d13153dd9e.a
Sketch uses 285879 bytes (27%) of program storage space. Maximum is 1044464 bytes.
Global variables use 35560 bytes (43%) of dynamic memory, leaving 46360 bytes for local variables. Maximum is 81920 bytes.
warning: espcomm_sync failed
error: espcomm_open failed
error: espcomm_upload_mem failed
error: espcomm_upload_mem failed[/code
My code is as follows:
[code]/* Example ESP8266 project for WiFi Access Point to read and dispaly sensor data.
* This code is modified from 42 BOTS to read temperature, pressure and altimeter data.
*/
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#define PA_to_InHg 2100
Adafruit_BMP280 bmp; // I2C
#define RED_LED_ESP8266 0
IPAddress apIP(192,168,4,100); //Define static IP Address: local & gateway
//Default IP in AP mode is 192.168.4.1
//Define WiFi Access Point settings
const char *ssid = "myESP8266";
const char *password = "pwESP8266";
//Use web server port 80
ESP8266WebServer server(80);
bool red_led_state = false;
float temp;
void handleRoot() {
//
char html[1000];
temp = bmp.readTemperature();
// Build an HTML page to display on the web-server root address
snprintf ( html, 1000,
"<html>\
<head>\
<meta http-equiv='refresh' content='8'/>\
<title>ESP8266 WiFi Network</title>\
<style>\
body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; font-size: 1.5em; Color: #000000; }\
h1 { Color: #AA0000; }\
</style>\
</head>\
<body>\
<h1>ESP8266 Wi-Fi Access Point and Sensor Application!</h1>\
<p>Temperature [C]: %3.1f%</p>\
<p>Pressure [In-Hg]: %3.2f%</p>\
<p>Altitude [m]: %3.2f%</p>\
<p>This page refreshes every 10 seconds. Click <a href=\"javascript:window.location.reload();\">here</a> to refresh the page now.</p>\
</body>\
</html>", temp, bmp.readPressure()/PA_to_InHg, bmp.readAltitude(643.6));
server.send ( 200, "text/html", html );
//
digitalWrite(RED_LED_ESP8266, LOW);
delay(1000);
digitalWrite(RED_LED_ESP8266, HIGH);
delay(1000);
}
void handleNotFound() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
//Build and send error message
String message = "File not found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += ( server.method() == HTTP_GET ) ? "GET" : "POST";
message += "\nArguments: ";
message += "\n";
for ( uint8_t i = 0; i < server.args(); i++ ) {
message += " " + server.argName ( i ) + ": " + server.arg ( i ) + "\n";
}
server.send ( 404, "text/plain", message ); //Send failed message to browser
//
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
}
void setup() {
// put your setup code here, to run once:
//RED LED used as OUTPUT.
pinMode(RED_LED_ESP8266, OUTPUT);
//Drive Bliknk RED LED Once on Start Up.
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000);
//Connect to serial port and display message for sensor & wifi.
Serial.begin(115200);
Serial.println();
//Locate Sensor
if (bmp.begin(0x77)) {
Serial.println(F("Found a valid BMP280 sensor!"));
}
else {
Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
while (1);
}
//Set up custom IP Address
Serial.println("Configuring Access Point ...");
WiFi.mode(WIFI_AP_STA);
WiFi.softAPConfig(apIP, apIP, IPAddress(255,255,255,0)); //Subnet 0xFF.0xFF.0xFF.0x00
WiFi.softAP(ssid); //Make access point open to all, use WiFi.softAP(ssid, password) for password login
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP Address: ");
Serial.println(myIP);
server.on( "/", handleRoot );
server.onNotFound( handleNotFound );
server.begin();
Serial.println("HTTP server started!");
}
void loop() {
// put your main code here, to run repeatedly:
//Handle server request
server.handleClient();
//Blink RED LED
//digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
//delay(100); // wait for a second
//digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
//delay(100);
}
I have attached a couple of photos of my set-up.
Thank you.
ANKAR