-
-
Save hmms/a4a2b3f9eaf32f3005fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <user_config.h> | |
#include <SmingCore/SmingCore.h> | |
#include <Libraries/BMP180/BMP180.h> | |
#include <Libraries/Sparkfun_HTU21DF/SparkFunHTU21D.h> | |
#ifndef WIFI_SSID | |
#define WIFI_SSID "##" // Put you SSID and Password here | |
#define WIFI_PWD "##" | |
#endif | |
//BMP180 barometer; | |
HTU21D htu21df_sensor; | |
HttpClient thingSpeak; | |
Timer procTimer; | |
float temp = 0; | |
float humd = 0; | |
float humd1 = 0; | |
void onDataSent(HttpClient& client, bool successful) | |
{ | |
if (successful) | |
Serial.println("Success sent"); | |
else | |
Serial.println("Failed"); | |
String response = client.getResponseString(); | |
Serial.println("Server response: '" + response + "'"); | |
if (response.length() > 0) | |
{ | |
int intVal = response.toInt(); | |
if (intVal == 0) | |
Serial.println("Sensor value wasn't accepted. May be we need to wait a little?"); | |
} | |
} | |
void sendData() | |
{ | |
if (thingSpeak.isProcessing()) return; // We need to wait while request processing was completed | |
Wire.begin(); | |
humd = htu21df_sensor.readHumidity(); | |
//temp = htu21df_sensor.readTemperature(); | |
Serial.print("\tHumidity: "); | |
Serial.print(String(humd)); | |
} | |
// Will be called when WiFi station was connected to AP | |
void connectOk() | |
{ | |
Serial.println("I'm CONNECTED"); | |
// Start send data loop | |
procTimer.initializeMs(1 * 1000, sendData).start(); // every 25 seconds | |
} | |
// Will be called when WiFi station timeout was reached | |
void connectFail() | |
{ | |
Serial.println("I'm NOT CONNECTED. Need help :("); | |
// Start soft access point | |
WifiAccessPoint.enable(true); | |
WifiAccessPoint.config("CONFIG ME PLEEEEASE...", "", AUTH_OPEN); | |
// .. some you code for configuration .. | |
} | |
void init() | |
{ | |
Serial.begin(SERIAL_BAUD_RATE); // 115200 by default | |
Serial.systemDebugOutput(true); // Allow debug output to serial | |
Wire.begin(); | |
Serial.println(); // Start a new line. | |
WifiStation.config(WIFI_SSID, WIFI_PWD); | |
WifiStation.enable(true); | |
WifiAccessPoint.enable(false); | |
WifiStation.waitConnection(connectOk, 20, connectFail); // We recommend 20+ seconds for | |
Serial.print("init complete"); | |
//while(1){ | |
//humd = readHumidity1(); | |
//temp = htu21df_sensor.readTemperature(); | |
//Serial.print("\tHumidity: "); | |
//Serial.print(String(humd)); | |
//humd1 = htu21df_sensor.readHumidity(); | |
//Serial.print("\tHumidity1: "); | |
//Serial.print(String(humd1)); | |
//delay(50000); | |
//} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment