From f2806ccce1e57dae7400372df1e59d5eab8e3c1b Mon Sep 17 00:00:00 2001 From: OMGiTzPomPom Date: Thu, 15 Sep 2022 16:17:37 +0200 Subject: [PATCH] tp1 --- tp1/arduino/LoRaReceiver/LoRaReceiver.ino | 31 ++++++++++++++++++++ tp1/arduino/LoRaSender/LoRaSender.ino | 35 +++++++++++++++++++++++ tp1/python/Lecture_portcom.py | 24 ++++++++++++++++ tp1/python/datas.csv | 10 +++++++ 4 files changed, 100 insertions(+) create mode 100644 tp1/arduino/LoRaReceiver/LoRaReceiver.ino create mode 100644 tp1/arduino/LoRaSender/LoRaSender.ino create mode 100644 tp1/python/Lecture_portcom.py create mode 100644 tp1/python/datas.csv diff --git a/tp1/arduino/LoRaReceiver/LoRaReceiver.ino b/tp1/arduino/LoRaReceiver/LoRaReceiver.ino new file mode 100644 index 0000000..4e99c0f --- /dev/null +++ b/tp1/arduino/LoRaReceiver/LoRaReceiver.ino @@ -0,0 +1,31 @@ +#include +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + + Serial.println("Applejack is best pony ! Received by Pauline Srifi ~"); + + if (!LoRa.begin(864E6)) { + Serial.println("Starting LoRa failed!"); + while (1); + } +} + +void loop() { + // try to parse packet + int packetSize = LoRa.parsePacket(); + if (packetSize) { + // received a packet + + // read packet + while (LoRa.available()) { + Serial.print((char)LoRa.read()); + } + + // print RSSI of packet + //Serial.print("' with RSSI "); + //Serial.println(LoRa.packetRssi()); + } +} diff --git a/tp1/arduino/LoRaSender/LoRaSender.ino b/tp1/arduino/LoRaSender/LoRaSender.ino new file mode 100644 index 0000000..be0d21a --- /dev/null +++ b/tp1/arduino/LoRaSender/LoRaSender.ino @@ -0,0 +1,35 @@ +#include +#include + +int counter = 0; + +void setup() { + Serial.begin(9600); + while (!Serial); + + Serial.println("Applejack is best pony ! Send by Pauline Srifi ~"); + + if (!LoRa.begin(864E6)) { + Serial.println("Starting LoRa failed!"); + while (1); + } +} + +int generateRandomTemp() { //-50 to 150 + int r = (rand() % (150 - (-50) + 1)) + (-50); + return r; +} + +void loop() { + int temp = generateRandomTemp(); + // send packet + LoRa.beginPacket(); + LoRa.print("Pauline temp is "); + LoRa.print(temp); + LoRa.println("°."); + LoRa.endPacket(); + + counter++; + + delay(5000); +} diff --git a/tp1/python/Lecture_portcom.py b/tp1/python/Lecture_portcom.py new file mode 100644 index 0000000..bd9b09d --- /dev/null +++ b/tp1/python/Lecture_portcom.py @@ -0,0 +1,24 @@ +import serial as s +import datetime + +ser=s.Serial() +ser.baudrate = 9600 +ser.port = "COM5" +ser.timeout=10 + +ser.open() +f=open('datas.csv','w') + +for uwu in range(0,10) : + x = ser.readline() + t = datetime.datetime.now() + + f.write(str(x)) + f.write("; ") + f.write(str(t)) + f.write("\n") + print("Écriture de la ligne " + str(uwu+1)) + +print("écriture finie") +f.close() +ser.close() diff --git a/tp1/python/datas.csv b/tp1/python/datas.csv new file mode 100644 index 0000000..9723172 --- /dev/null +++ b/tp1/python/datas.csv @@ -0,0 +1,10 @@ +b'Applejack is best pony ! Received by Pauline Srifi ~\r\n'; 2022-09-15 16:16:06.340607 +b'h%l\xcc\x12.\x9d\x14\x13Pauline temp is 115\xc2\xb0.\r\n'; 2022-09-15 16:16:09.275030 +b'Pauline temp is 121\xc2\xb0.\r\n'; 2022-09-15 16:16:14.333684 +b'Pauline temp is -1\xc2\xb0.\r\n'; 2022-09-15 16:16:19.390743 +b'Pauline temp is -43\xc2\xb0.\r\n'; 2022-09-15 16:16:24.449501 +b'Pauline temp is -26\xc2\xb0.\r\n'; 2022-09-15 16:16:29.507680 +b'Pauline temp is -24\xc2\xb0.\r\n'; 2022-09-15 16:16:34.566655 +b'Pauline temp is 112\xc2\xb0.\r\n'; 2022-09-15 16:16:39.624938 +b'Pauline temp is -50\xc2\xb0.\r\n'; 2022-09-15 16:16:44.681967 +b'Pauline temp is -2\xc2\xb0.\r\n'; 2022-09-15 16:16:49.740181