Merge branch 'main' of https://gitlab.fdmci.hva.nl/propedeuse-hbo-ict/onderwijs/2023-2024/out-a-se-ti/blok-3/qaajeeqiinii59
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
#include "DHT.h"
|
||||
#include <WiFi.h>
|
||||
#include <WiFiMulti.h>
|
||||
#include <WebSocketsClient.h>
|
||||
|
||||
#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) + "\"}");
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
### 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.
|
||||
|
||||
#### The loop
|
||||
We start with setting a timer because a "delay" function would break the connection with the websocket resulting in an error.
|
||||
|
||||
This relates back to some some variables that were made in the beginning.
|
||||
|
||||
We make variables for the different results we are gathering, so these can be used later.
|
||||
|
||||
Then the variables get printed for overview.
|
||||
|
||||
To ensure the websocket connection , the process gets looped.
|
||||
|
||||
#### Update File.
|
||||
Here the text thathas te be sent to the websocket gets sent.
|
||||
|
||||
### The fysical product.
|
||||
it is shown here:
|
||||

|
||||
It also turns on:
|
||||

|
||||
|
||||
Here are my fritzing and wireframe, the components used are shown but The DHT11 is replaced by a DHT22.
|
||||

|
||||

|
||||
|
||||
### The code.
|
||||
Here the c++ code is shown:
|
||||
https://gitlab.fdmci.hva.nl/propedeuse-hbo-ict/onderwijs/2023-2024/out-a-se-ti/blok-3/qaajeeqiinii59/-/blob/main/docs/LearningProcessBram/ArduinoExperience/NodeWithWebConnection.ino?ref_type=heads
|
BIN
docs/LearningProcessBram/ArduinoExperience/image.png
Normal file
BIN
docs/LearningProcessBram/ArduinoExperience/image.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 96 KiB |
BIN
docs/LearningProcessBram/documentatie/assets/2Covers.jpg
Normal file
BIN
docs/LearningProcessBram/documentatie/assets/2Covers.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 492 KiB |
@@ -43,8 +43,8 @@ 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
|
||||
|
||||
/Sebas : plastic looks better and goes straight to the point.
|
||||
|
Reference in New Issue
Block a user