temperature and humidity sensing - clean
This commit is contained in:
parent
0576b54da1
commit
17b218ca47
@ -1,30 +0,0 @@
|
||||
#include <Wire.h>
|
||||
|
||||
void setup() {
|
||||
Wire.begin();
|
||||
Serial.begin(9600);
|
||||
while (!Serial);
|
||||
Serial.println("I2C Scanner");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
byte error, address;
|
||||
int count = 0;
|
||||
|
||||
for (address = 1; address < 127; address++) {
|
||||
Serial.println("Scanning address {address}");
|
||||
Wire.beginTransmission(address);
|
||||
error = Wire.endTransmission();
|
||||
Serial.print(error);
|
||||
|
||||
if (error == 0) {
|
||||
Serial.print("I2C device found at 0x");
|
||||
Serial.println(address, HEX);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 0) Serial.println("No I2C devices found");
|
||||
|
||||
delay(2000);
|
||||
}
|
@ -1,155 +0,0 @@
|
||||
// SHT31 configuration
|
||||
#include "Adafruit_SHT31.h"
|
||||
|
||||
Adafruit_SHT31 sht31 = Adafruit_SHT31();
|
||||
|
||||
#define SHT31_RST_PIN 16
|
||||
|
||||
void resetSensor() {
|
||||
pinMode(SHT31_RST_PIN, OUTPUT);
|
||||
digitalWrite(SHT31_RST_PIN, LOW);
|
||||
delay(10);
|
||||
digitalWrite(SHT31_RST_PIN, HIGH);
|
||||
delay(10);
|
||||
}
|
||||
//
|
||||
// W5500 configuration
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
|
||||
// Configure MAC address and IP:
|
||||
byte mac[] = { 0x97, 0x8A, 0xC5, 0x86, 0xA4, 0xEF };
|
||||
char T[8];
|
||||
char H[8];
|
||||
char message[20];
|
||||
|
||||
|
||||
// the real one IPAddress ip(10, 11, 1, 22); // Static IP
|
||||
|
||||
|
||||
// Define CS and RST pins:
|
||||
#define W5500_CS_PIN 10 // 8 in E LEGO
|
||||
#define W5500_RST_PIN 9 //10 in E LEGO
|
||||
//IPAddress serverIP(10, 44, 1, 238); // Computer
|
||||
//IPAddress W5500_ip(10, 44, 1, 22); // Change the last digit
|
||||
IPAddress serverIP(10, 44, 1, 238);
|
||||
IPAddress W5500_ip(10, 11, 1, 46);
|
||||
IPAddress gateway(10, 11, 1, 1);
|
||||
IPAddress DNS(147,142,19,254);
|
||||
IPAddress subnet(255, 255, 255, 0);
|
||||
|
||||
|
||||
|
||||
// Don't change
|
||||
const int port = 5005;
|
||||
EthernetClient client;
|
||||
//
|
||||
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
|
||||
// SHT31 First readout
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
;
|
||||
Serial.println("Looking for SHT31");
|
||||
|
||||
if (!sht31.begin(0X44)) {
|
||||
Serial.println("Couldn't find SHT31");
|
||||
while (1) delay(100);
|
||||
}
|
||||
Serial.println("SHT31 Found");
|
||||
float t = sht31.readTemperature();
|
||||
float h = sht31.readHumidity();
|
||||
|
||||
if (!isnan(t)) {
|
||||
Serial.print("Temperature (C)= ");
|
||||
Serial.println(t);
|
||||
}
|
||||
|
||||
if (!isnan(h)) {
|
||||
Serial.print("Humidity = ");
|
||||
Serial.println(h);
|
||||
}
|
||||
|
||||
|
||||
// W5500 first readout
|
||||
pinMode(W5500_RST_PIN, OUTPUT);
|
||||
digitalWrite(W5500_RST_PIN, HIGH);
|
||||
delay(250);
|
||||
digitalWrite(W5500_RST_PIN, LOW);
|
||||
delay(250);
|
||||
digitalWrite(W5500_RST_PIN, HIGH);
|
||||
delay(1000);
|
||||
|
||||
// Initialize Ethernet:
|
||||
Ethernet.init(W5500_CS_PIN);
|
||||
Ethernet.begin(mac, W5500_ip, DNS, gateway, subnet);
|
||||
|
||||
delay(1500);
|
||||
Serial.print("W5500 IP: ");
|
||||
Serial.println(Ethernet.localIP());
|
||||
|
||||
// Send a message through socket
|
||||
Serial.println("Sending test message");
|
||||
delay(1000);
|
||||
if (client.connect(serverIP, port)) {
|
||||
client.write("Connection check");
|
||||
client.stop();
|
||||
Serial.println("Test Message sent");
|
||||
} else {
|
||||
Serial.println("Connection failed");
|
||||
while(1);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
// Measure temp. and humidity every 30 seconds
|
||||
delay(15000);
|
||||
float t = sht31.readTemperature();
|
||||
float h = sht31.readHumidity();
|
||||
// Send to Eilon's computer
|
||||
if (client.connect(serverIP, port)) {
|
||||
client.write("Temp");
|
||||
client.stop();
|
||||
} else {
|
||||
Serial.println("Connection failed");
|
||||
}
|
||||
if (client.connect(serverIP, port)) {
|
||||
if (!isnan(t)) {
|
||||
dtostrf(t, 6, 2, T);
|
||||
snprintf(message, sizeof(message), "T %s", T);
|
||||
Serial.println(message);
|
||||
//client.write((const uint8_t*)message, strlen(message)); // Send to server
|
||||
client.write(T);
|
||||
client.stop();
|
||||
Serial.println("message sent");
|
||||
}
|
||||
|
||||
} else {
|
||||
Serial.println("Connection failed");
|
||||
}
|
||||
delay(15000);
|
||||
if (client.connect(serverIP, port)) {
|
||||
client.write("Humidity");
|
||||
client.stop();
|
||||
} else {
|
||||
Serial.println("Connection failed");
|
||||
}
|
||||
|
||||
if (client.connect(serverIP, port)) {
|
||||
if (!isnan(h)) {
|
||||
dtostrf(h, 6, 2, H);
|
||||
snprintf(message, sizeof(message), "H %s", H);
|
||||
Serial.println(message);
|
||||
client.write(H);
|
||||
//client.write((const uint8_t*)message, strlen(message)); // Send to server
|
||||
client.stop();
|
||||
Serial.println("message sent");
|
||||
}
|
||||
} else {
|
||||
Serial.println("Connection failed");
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
2025-07-01 12:07:23,564 - INFO - Logger set up complete
|
||||
2025-07-01 12:07:23,564 - INFO - Reading the temperature on Phillip's desk
|
||||
2025-07-01 12:07:28,770 - INFO - Logger set up complete
|
||||
2025-07-01 12:07:28,770 - INFO - Reading the temperature on Phillip's desk
|
@ -21,7 +21,7 @@ IPAddress gateway(10, 11, 1, 1);
|
||||
IPAddress subnet(255, 255, 255, 0);
|
||||
|
||||
// Server to connect to
|
||||
IPAddress server(10, 44, 1, 238);
|
||||
IPAddress server(147, 142, 16, 73);
|
||||
const int serverPort = 5005; // Change to the port your server listens on
|
||||
|
||||
EthernetClient client;
|
Loading…
Reference in New Issue
Block a user