Last active
October 26, 2022 12:43
-
-
Save GillesC/786174caf97557300fb6c3a5771014f2 to your computer and use it in GitHub Desktop.
Session Stijn Wielandt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Bucket 1: 8KtxZHGarAcAFJdGhSJ0Gl-KmTqWqmrP6Tq5RvbmjvkZk7p0WLH9KIStedRD3au4cx3yY1VGpWGEyrdqh5ZAFQ== | |
Bucket 2: a7RzE69Aij03tsQP5YyB1vptJLvVoG4PR0o1ZSS7Ogn_p16ANWiOhzB5LjuWwMnw3YqvDgD6VPFvKQtIo2xZUw== | |
Bucket 3: fOy9Lqg4Uyek4SbFH3ANlo0g3qyUmwG8zrcQZdr-wnurC0DID9lHUKH_mDjWdxEMY2bL02T08Kmh9JQ-lSiQew== | |
Bucket 4: NFSpkLX0laz8RpD7ZSLL7EFzft7ABOx0F7LqkgKijEH86JRmtWgO8bJqs80bD2uXxRVASOpvSgdDzU_7BhFhsA== | |
Bucket 5: lOzOwcIPx_oRIByRLr9ewtclBZNE6_0WWU57dIgKItDVHdEAf9C6kLQpe7r1cjJI8uksBHPijJ7sm8YB2IQowA== | |
Bucket 6: OrPts4Ry3xUvPPCP8O4zXzySBBBu9j-vncA0pXkfBUi77BOOUp3lqFKErwyCmepNiJVQqC6ZSzksZpRGb_bOqA== | |
Bucket 7: HEpn7LnGYokoPNSzqwk9LQByu-KV15_OYGCtfLUBJOWF0EOpuQtf7O71gZsKNam4P0zc8Bd4gaRv8B7v7p7YrA== | |
Bucket 8: MLSqFShpDtfa3V4X1KGuYFhRo9Q3_uTppErbY8SVqnHNovv3INvi0Mdbw63bv_x_KlWunHU-QmL8X_SR-ucVhA== | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://github.com/dramco-edu/wifi-mqtt-esp32 | |
Broker: 52.28.129.241 | |
Influxdb: 192.168.1.20:8086 username: stijn pwd: just4now |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
np.seterr(divide='ignore', invalid='ignore') | |
import paho.mqtt.client as mqtt | |
import pandas as pd | |
import pickle | |
import os | |
import copy | |
from datetime import datetime, timedelta | |
from influxdb_client import InfluxDBClient, Point, WritePrecision, WriteOptions | |
from influxdb_client.client.write_api import SYNCHRONOUS | |
from pathlib import Path | |
token = "" # TODO change | |
org = "KUL" | |
bucket = "bucketX" #TODO change | |
TOPIC = "nieuwpoort/X" #TODO change | |
MQTT_SERVER = "broker.hivemq.com" | |
units = ['h', 'min', 's'] | |
def publish_parameters(message:float): | |
write_api = influx_client.write_api(write_options=SYNCHRONOUS) | |
#TODO change | |
p = Point("Node").field("temperature", message).time(time=datetime.utcnow() )#- timedelta(minutes=80)) | |
write_api.write(bucket = bucket, record = p) | |
#influx_DB = InfluxDBClient(url='192.168.1.20:8086', token = ALL_token, org = org) | |
#write_api_DB = influx_DB.write_api(write_options=SYNCHRONOUS) | |
#dT, dA = Create_Dataframe(message, sample) | |
# print(dT) | |
# print(dA) | |
# write_api_DB.write(message.topic, org, record=dT, data_frame_measurement_name = "Node"+f'{(message.node_ID-message.repeater):03d}') | |
# Convert raw to hex to readable format | |
def raw2real(topic, payload): | |
#convert data to float value | |
#TODO change | |
publish_parameters(payload) | |
# The callback for when the client receives a CONNACK response from the server. | |
def on_connect(client, userdata, flags, rc): | |
print("Connected with result code "+str(rc)) | |
client.subscribe(TOPIC, 1)#"#") | |
# The callback for when a PUBLISH message is received from the server. | |
def on_message(client, userdata, msg): | |
#write_api = influx_client.write_api(write_options=SYNCHRONOUS) | |
payload = msg.payload | |
if((msg.topic == TOPIC) and len(payload) > 1): | |
print("--------------------------------------------") | |
print(msg.topic + " " + str(payload)) | |
raw2real(msg.topic, payload) | |
# Set up In | |
influx_client = InfluxDBClient(url='192.168.1.20:8086', token = token, org = org) | |
client = mqtt.Client() | |
client.on_connect = on_connect | |
client.on_message = on_message | |
#client.username_pw_set(username=MQTT_USERNAME, password=MQTT_PASSWORD) | |
client.connect(MQTT_SERVER, 1883, 60) | |
# Blocking call that processes network traffic, dispatches callbacks and | |
# handles reconnecting. | |
# Other loop*() functions are available that give a threaded interface and a | |
# manual interface. | |
client.loop_forever() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Arduino.h" | |
#include <WiFi.h> | |
// Replace with your network credentials | |
const char *ssid = "NETGEAR68"; | |
const char *password = "excitedtuba713"; | |
// Intermal temperature sensor function declaration | |
#ifdef __cplusplus | |
extern "C" | |
{ | |
#endif | |
uint8_t temprature_sens_read(); | |
#ifdef __cplusplus | |
} | |
#endif | |
uint8_t temprature_sens_read(); // declare intermal temperature sensor function | |
uint32_t n; // number of measurement | |
uint32_t timer; // time from start | |
uint32_t tm1; // start moment | |
void setup() | |
{ | |
Serial.begin(115200); | |
// Standart Wi-Fi connection | |
WiFi.begin(ssid, password); | |
while (WiFi.status() != WL_CONNECTED) | |
{ | |
delay(500); | |
Serial.print("."); | |
} | |
Serial.println(""); | |
Serial.println("WiFi connected"); | |
Serial.println(WiFi.localIP()); | |
// Table headers in serial monitor number, time(minutes), temperature Celsius | |
Serial.print("Number\t"); | |
Serial.print("time\t"); | |
Serial.print("temp,C*\n"); | |
int n = 0; // set measurement number to 0 at setup | |
tm1 = millis(); // set start moment to millis at setup | |
} | |
void loop() | |
{ | |
// do something your's, for example increment c-variable | |
uint8_t c; | |
c++; | |
// read internal sensor and print to Serial | |
if ((temprature_sens_read()) != 128) | |
{ // ignore 128 (53.33 C) measurement | |
n++; // number increment | |
Serial.print(n); | |
Serial.print("\t"); // print number and tab | |
timer = millis() - tm1; // get meassurement moment | |
Serial.print(timer / 60000.0); | |
Serial.print("\t"); // print measurement time (minutes) and tab | |
Serial.print((temprature_sens_read() - 32) / 1.8); // print Celsius temperature and tab | |
Serial.print("\n"); // print new line | |
delay(1000); // read temperature 1 times per sec | |
} | |
delay(1000); // delay in loop | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment