Skip to content

Commit

Permalink
Merge pull request #1 from MecaHumArduino/wifi
Browse files Browse the repository at this point in the history
Wifi
  • Loading branch information
isbkch committed Sep 24, 2020
2 parents b262d30 + c12570e commit ac62eed
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
.vscode/ipch
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ board = uno
framework = arduino
lib_extra_dirs = ~/Documents/Arduino/libraries
monitor_speed = 9600
serial_port = /dev/cu.usbserial-A50285BI
71 changes: 61 additions & 10 deletions src/main.ino
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
#include <dht11.h>
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>

#define DHT11PIN 3
#define DEBUG true
#define DHT11PIN 4
dht11 sensor;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

// ESP TX => Uno Pin 2
// ESP RX => Uno Pin 3
SoftwareSerial wifi(2, 3);

void setup() {
Serial.begin(9600);
wifi.begin(9600);

// set up the LCD's number of columns and rows
lcd.begin(16, 2);
Expand All @@ -29,26 +36,70 @@ void setup() {

void loop() {

Serial.print("buffer: ");
if (wifi.available()) {
String espBuf;
long int time = millis();

while( (time+1000) > millis()) {
while (wifi.available()) {
// The esp has data so display its output to the serial window
char c = wifi.read(); // read the next character.
espBuf += c;
}
}
Serial.print(espBuf);
}
Serial.println(" endbuffer");

// read from the digital pin
int check = sensor.read(DHT11PIN);
int check = sensor.read(DHT11PIN);
float temperature = (float)sensor.temperature;
float humidity = (float)sensor.humidity;

// display Hum on the LCD screen
lcd.setCursor(0, 0);
lcd.print("Humidity (%): ");
lcd.print((float)sensor.humidity, 2);
lcd.print(humidity, 2);

// display Temp on the LCD screen
lcd.setCursor(0, 1);
lcd.print("Temp (C): ");
lcd.print((float)sensor.temperature, 2);
lcd.print(temperature, 2);

// print Hum on the serial monitor
Serial.print("Humidity (%): ");
Serial.println((float)sensor.humidity, 2);
// const char DATA_TO_SEND[] = "{\"Humidity\":\"" + (String)humidity + "\", \"Temperature\":\"" + (String)temperature + "\"} ";

// print Temp on the serial monitor
Serial.print("Temperature (C): ");
Serial.println((float)sensor.temperature, 2);

String sensorData = "{\"Humidity\":\"";
sensorData += (String)humidity;
sensorData += "\", \"Temperature\":\"";
sensorData += (String)temperature;
sensorData += "\"}";
sensorData += "\r\n";

Serial.println(sensorData);
sendDataToWiFi(sensorData, 1000, DEBUG);

delay(2000); // take measurements every 2 sec
}

String sendDataToWiFi(String command, const int timeout, boolean debug)
{
String response = "";

wifi.print(command); // send the read character to the esp8266

long int time = millis();

while((time+timeout) > millis()) {
while(wifi.available()) {
// The esp has data so display its output to the serial window
char c = wifi.read(); // read the next character.
response+=c;
}
}

Serial.print(response);

return response;
}

0 comments on commit ac62eed

Please sign in to comment.