Skip to content

Instantly share code, notes, and snippets.

@hmms
Created November 28, 2015 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hmms/97418ce0801189e6fd64 to your computer and use it in GitHub Desktop.
Save hmms/97418ce0801189e6fd64 to your computer and use it in GitHub Desktop.
#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 "NETGEAR73" // Put you SSID and Password here
#define WIFI_PWD "niftyonion864"
#endif
#define SHIFTED_DIVISOR 0x988000
//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){
//Serial.print("\tHumidity: ");
//Serial.print(String(humd));
humd = htu21df_sensor.readHumidity();
Serial.print("\tHumidity1: ");
Serial.print(String(humd));
delay(1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment