diff --git a/docs/LearningProcessBram/ArduinoExperience/NodeWithWebConnection.ino b/docs/LearningProcessBram/ArduinoExperience/NodeWithWebConnection.ino new file mode 100644 index 0000000..32fdc21 --- /dev/null +++ b/docs/LearningProcessBram/ArduinoExperience/NodeWithWebConnection.ino @@ -0,0 +1,86 @@ +#include "DHT.h" +#include +#include +#include + +#define DHTPIN 4 +#define DHTTYPE DHT11 + +uint8_t h; +uint8_t t; + +uint16_t interval = 5000; +unsigned long currentMillis; +unsigned long lastMillis; + +WiFiMulti wifiMulti; +WebSocketsClient webSocket; + +DHT dht(DHTPIN, DHTTYPE); + +void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) { + // Handle WebSocket events here if needed +} + +void setup() { + Serial.begin(9600); + Serial.println(F("DHTxx test!")); + dht.begin(); + + wifiMulti.addAP("iotroam", "sGMINiJDcU"); + wifiMulti.addAP("Ziggo6565749", "Ziggobroek1@"); + + Serial.println("Connecting Wifi..."); + if (wifiMulti.run() == WL_CONNECTED) { + Serial.println(""); + Serial.println("WiFi connected"); + Serial.println("IP address: "); + Serial.println(WiFi.localIP()); + + // Connect to WebSocket server + webSocket.begin("145.92.8.114", 80, "/ws"); // Replace with your Raspberry Pi's IP address and port + webSocket.onEvent(webSocketEvent); + webSocket.setReconnectInterval(500); + } +} + +void loop() { + + // update when interval is met + if (currentMillis - lastMillis >= interval){ + lastMillis = millis(); + update(); + } + + // update the counter + currentMillis = millis(); + + float h = dht.readHumidity(); + // Read temperature as Celsius (the default) + float t = dht.readTemperature(); + + if (isnan(h) || isnan(t)) { + Serial.println(F("Failed to read from DHT sensor!")); + return; + } + + // Compute heat index in Celsius (isFahrenheit = false) + float hic = dht.computeHeatIndex(t, h, false); + + Serial.print(F("Humidity: ")); + Serial.print(h); + Serial.print(F("% Temperature: ")); + Serial.print(t); + Serial.print(F("°C ")); + Serial.print(hic); + Serial.print(F("°C ")); + + + + // Ensure WebSocket communication + webSocket.loop(); +} + +void update(){ + webSocket.sendTXT("{\"node\": \"" + String(WiFi.macAddress()) + "\", \"Temp\":\"" + String(t) + "\",\"Humi\":\"" + String(h) + "\"}"); +} \ No newline at end of file diff --git a/docs/LearningProcessBram/ArduinoExperience/NodeWithWebConnection.md b/docs/LearningProcessBram/ArduinoExperience/NodeWithWebConnection.md new file mode 100644 index 0000000..6fb2487 --- /dev/null +++ b/docs/LearningProcessBram/ArduinoExperience/NodeWithWebConnection.md @@ -0,0 +1,25 @@ +### Connecting With The websocket. +#### The reason. +During our project we needed more esp's to connect to the websocket, so i was given the task to make a connection to wifi, connect to the websocket, and then send information to it. + +#### Before the setup. +I used library's for: connecting to multiple wifi's, connecting to the websocket and being able to read infromation form a DHT11. +These were called uppon in the first few lines. + +Together with this a few variables are named to be used later in the code. + +#### The Setup +Firstoff, start with identifying which serial port will be used and work from there. +It Then tells the DHT to send a test message and start it up. + +Then the several wifi connections get told here and it looks for the one that connects. +(This is made bij giving the wifi name and pasword) +In this sequence a print is made, showing that there is an atempt to connect to a wifi. + +*This was used because the node should be able to connect to several wifi's and not be stuck t one in perticulair. + +After the wifi is connected it sends a print to indicate a connection and pings the ip adress of the used wifi. + +The websocket connection which was then made is made using the uri, port, and type of connection. +In case of websocket events it gets sent. +In case of connection failiure, try this. \ No newline at end of file diff --git a/docs/brainstorm/Feedback.md b/docs/brainstorm/Feedback.md index 84428c0..64205c7 100644 --- a/docs/brainstorm/Feedback.md +++ b/docs/brainstorm/Feedback.md @@ -43,7 +43,7 @@ The Plastic: less eco-friendly, takes a longer time, looks objectively better. since we can't decide on what we should use, I (Bram) went out to asks the public for their opinion. To do this i took the front of the plastic design, and the front of the wooden design. -They lloked like this: +They looked like this: 1. which design is more likable