Hi all,
in summary, i'm not a computer scientist....
I'm trying to send temperature and humidity with wi-fi...
For this, I would like to merge the both sketchs in the following because I'm working with SHT sensors and not DHT
Is there someone who can help me to resolve this hurdle?
In fact I met some errors during compilation in accordance with "float" declaration, location in sketch... aRest can't manage float variables, so I need probably to work with a kind of FloatToString function... but I never succeed it.
Simple SHT read sketch
#include <SHT1x.h>
#define dataPin 7
#define clockPin 6
SHT1x sht1x(dataPin, clockPin);
void setup()
{
Serial.begin(9600);
}
void loop()
{
float temp_c;
float humidity;
temp_c = sht1x.readTemperatureC();
humidity = sht1x.readHumidity();
Serial.print("Temperature: ");
Serial.print(temp_c);
Serial.print("C / ");
Serial.print(humidity);
Serial.println("%");
delay(2000);
}
Weather Station sketch example with DHT
#define NUMBER_VARIABLES 2
#define NUMBER_FUNCTIONS 1
#include <Adafruit_CC3000.h>
#include <SPI.h>
#include <CC3000_MDNS.h>
#include <aREST.h>
#include "DHT.h"
#define ADAFRUIT_CC3000_IRQ 3
#define ADAFRUIT_CC3000_VBAT 5
#define ADAFRUIT_CC3000_CS 10
#define WLAN_SSID "yourWiFiName"
#define WLAN_PASS "yourWiFiPassword"
#define WLAN_SECURITY WLAN_SEC_WPA2
#define DHTPIN 7
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, SPI_CLOCK_DIV2);
aREST rest = aREST();
#define LISTEN_PORT 80
Adafruit_CC3000_Server restServer(LISTEN_PORT);
MDNSResponder mdns;
int temperature;
int humidity;
//-------------------------------------------------------------------------------------------------------
void setup(void)
{
Serial.begin(9600);
rest.variable("temperature",&temperature);
rest.variable("humidity",&humidity);
rest.set_id("1");
rest.set_name("weather_station");
dht.begin();
if (!cc3000.begin())
{
while(1);
}
cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);
while (!cc3000.checkDHCP())
{
delay(100);
}
if (!mdns.begin("arduino", cc3000)) {
while(1);
}
restServer.begin();
displayConnectionDetails();
}
//-------------------------------------------------------------------------------------------------------
void loop(void)
{
temperature = (uint8_t)dht.readTemperature();
humidity = (uint8_t)dht.readHumidity();
mdns.update();
Adafruit_CC3000_ClientRef client = restServer.available();
rest.handle(client);
}
//-------------------------------------------------------------------------------------------------------
bool displayConnectionDetails(void)
{
uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
{
return false;
}
else
{
Serial.println(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress);
return true;
}
}