Project Arduino, BMP180, DHT11 & ThingSpeak | Arduino | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
Project Arduino, BMP180, DHT11 & ThingSpeak
No permission to create posts
August 6, 2015
10:58 am
Avatar
Igor_Klc
New Member
Members
Forum Posts: 1
Member Since:
August 6, 2015
sp_UserOfflineSmall Offline

Hello everyone! I am doing project for course on my faculty. Here is little description:

Components for the project:
Arduino Mega ADK board
Arduino Ethernet shield
DHT11 humidity sensor
BMP180 temperature and air pressure sensor

The program should do next. The sensors have to measure the temperature, pressure and humidity of air in the room, every measured data is saved to its variable which would later be updated to ThingSpeak channel. Also, Arduino would take information for outside temperature, pressure and humidity of air from some website with those data for a certain city (Ljubljana), and these data would also be sent to ThingSpeak so we could see and compare graphs for indoor and outdoor data.

I wrote 3 codes (one for sensors, one for Ethernet and one for ThingSpeak), and now I have combined them, but I have two error messages, and I need help to get rid of them. Every measured data is saved to its variable. Downloaded data from website is also saved to its variable.

Here is code:
#include
#include
#include
#include
#include

#define dht_apin A0 // Analog Pin sensor is connected to

Adafruit_BMP085 bmp;
dht DHT;

float localTemp;
float localPress;
float localHumid;
float FMF;

//------------ETHERNET--------------
byte mac[] = { 0xD4, 0x28, 0xB2, 0xFF, 0xA0, 0x73 };

IPAddress ip(193, 2, 68, 140);

// fill in your Domain Name Server address here:
IPAddress myDns(1, 1, 1, 1);

// initialize the library instance:
EthernetClient client;

char server[] = "meteo.fmf.uni-lj.si/";

unsigned long lastConnectionTime = 0;
const unsigned long postingInterval = 60L * 1000L;

//-----------THINGSPEAK---------------
byte server1[] = { 184, 106, 153, 149 }; // IP Address for the ThingSpeak API

String writeAPIKey = "5NK4YXIIHW0KCLT7";
const unsigned long updateInterval = 60000;
boolean lastConnected = false;

void setup() {
Serial.begin(9600);
bmp.begin();
delay(1000); // Delay to let system boot
startEthernetDHCP();
//-------------ETHERNET
while (!Serial) {
;
}
Ethernet.begin(mac, ip, myDns);
}

void loop() {

// BMP180 - temperature and pressure measurement
Serial.print("Current Temperature is: "); // temperature
Serial.print(bmp.readTemperature());
Serial.println(" Celsius");
localTemp=bmp.readTemperature();

Serial.print("Current Pressure is: "); // pressure
Serial.print(bmp.readPressure());
Serial.println(" Pa");
localPress=bmp.readPressure();

// DHT11 - humidity measurement
DHT.read11(dht_apin);

Serial.print("Current Humidity is: "); // humidity
Serial.print(DHT.humidity);
Serial.println(" %");
Serial.println(" "); // space between next group measurement
localHumid=DHT.humidity;

delay(60000); // Wait 60 seconds before new measurement

//--------------ETHERNET---------------
if (client.available()) {
char c = client.read();
Serial.write(c);
FMF=client.read();
}

if (millis() - lastConnectionTime > postingInterval) {
httpRequest();
}
}

// this method makes a HTTP connection to the server:
void httpRequest() {

client.stop();

// if there's a successful connection:
if (client.connect(server, 80)) {
Serial.println("connecting...");
// send the HTTP PUT request:
client.println("GET /latest.txt HTTP/1.1");
client.println("Host: http://www.arduino.cc");
client.println("User-Agent: arduino-ethernet");
client.println("Connection: close");
client.println();

// note the time that the connection was made:
lastConnectionTime = millis();
}
else {
// if you couldn't make a connection:
Serial.println("connection failed");
}

//----------THINGSPEAK--------------
if (client.available())
{
char c = client.read();
Serial.print(c);
}

if (!client.connected() && lastConnected)
{
Serial.println("...disconnected.");
client.stop();
}

if(!client.connected() && (millis() - lastConnectionTime > updateInterval))
updateThingSpeak("field1="+localTemp+"&field2="+localPress+"&field3="+localHumid+"&field4="+FMF);

lastConnected = client.connected();
}

void updateThingSpeak(String tsData)
{
if (client.connect(server,80))
{
Serial.println("Connected to ThingSpeak...");
Serial.println();
client.print("POST /update HTTP/1.1
");
client.print("Host: api.thingspeak.com
");
client.print("Connection: close
");
client.print("X-THINGSPEAKAPIKEY: " + writeAPIKey + "
");
client.print("Content-Type: application/x-www-form-urlencoded
");
client.print("Content-Length: ");
client.print(tsData.length());
client.print("
");
client.print(tsData);
lastConnectionTime = millis();
}

else
{
Serial.println("Connection Failed.");
Serial.println();
lastConnectionTime = millis();
}
}

void startEthernetDHCP()
{
while (Ethernet.begin(mac) != 1)
{
Serial.println("Error getting IP address via DHCP, trying again...");
delay(10000);
}

Serial.print("Moj naslov IP: ");

for (byte thisByte = 0; thisByte < 4; thisByte++)
{
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println();
}

Errors:
PROGRAM.ino: In function 'void httpRequest()':
PROGRAM:131: error: invalid operands of types 'const char [8]' and 'float' to binary 'operator+'
invalid operands of types 'const char [8]' and 'float' to binary 'operator+'

I already removed one error which was here:
//----------ETHERNET--------
char server[] = "meteo.fmf.uni-lj.si/";
unsigned long lastConnectionTime = 0;
const unsigned long postingInterval = 60L * 1000L;

//-----------THINGSPEAK---------------
byte server[] = { 184, 106, 153, 149 };

I had to change name for one of servers, so I changed byte server[] to byte server1[].

Can You help me with other two errors?

Thank You all!

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
19 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 272

Vinod: 240

piajola: 95

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 8665

Moderators: 1

Admins: 2

Forum Stats:

Groups: 3

Forums: 14

Topics: 1600

Posts: 5760

Newest Members:

Team_mafia, icXu, emorphistechno, VTVMART, manimozhi, adamhebrew

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457