Compare commits
No commits in common. "88fc81702706c2ae867f20bb51ace57735254ee5" and "02583b9497541ae6edf82c7e12d3fda1e905d571" have entirely different histories.
88fc817027
...
02583b9497
2 changed files with 99 additions and 21 deletions
22
main.py
22
main.py
|
@ -7,25 +7,17 @@
|
||||||
import serial
|
import serial
|
||||||
import time
|
import time
|
||||||
|
|
||||||
ser = serial.Serial('/dev/ttyACM0', baudrate = 9600, timeout = 6)
|
ser = serial.Serial('/dev/ttyACM0', baudrate = 9600, timeout = 1)
|
||||||
|
|
||||||
#time.sleep(3)
|
#time.sleep(3)
|
||||||
|
|
||||||
#ser.readline()
|
|
||||||
while 1:
|
|
||||||
# ser.readline()
|
|
||||||
Data = ser.readline().decode('ascii')
|
|
||||||
print(Data)
|
|
||||||
#outFile = open("arduino-fridge-powercontrol.json", "w")
|
|
||||||
#outFile.write(Data)
|
|
||||||
#outFile.close
|
|
||||||
|
|
||||||
##while 1:
|
while 1:
|
||||||
## # { "command": "switch", "arg": "one", "state": "off", "ver":"1690931931"}
|
# { "command": "switch", "arg": "one", "state": "off", "ver":"1690931931"}
|
||||||
## userInput = input('> ')
|
userInput = input('> ')
|
||||||
## ser.write(str(userInput).encode('ascii'))
|
ser.write(str(userInput).encode('ascii'))
|
||||||
## arduinoData = ser.readline().decode('ascii')
|
arduinoData = ser.readline().decode('ascii')
|
||||||
## print(arduinoData)
|
print(arduinoData)
|
||||||
|
|
||||||
|
|
||||||
##def getValues():
|
##def getValues():
|
||||||
|
|
|
@ -36,21 +36,67 @@ bool fetState2;
|
||||||
|
|
||||||
uint8_t addrSensor1[8] = { 0x28, 0xFF, 0x64, 0x1F, 0x79, 0xD1, 0xB1, 0x75 };
|
uint8_t addrSensor1[8] = { 0x28, 0xFF, 0x64, 0x1F, 0x79, 0xD1, 0xB1, 0x75 };
|
||||||
uint8_t addrSensor2[8] = { 0x28, 0xFF, 0x64, 0x1F, 0x79, 0xD7, 0xDA, 0x9A };
|
uint8_t addrSensor2[8] = { 0x28, 0xFF, 0x64, 0x1F, 0x79, 0xD7, 0xDA, 0x9A };
|
||||||
|
/*
|
||||||
|
|
||||||
|
// countLowTemp
|
||||||
|
int cLTemp1 = 0;
|
||||||
|
int cLTemp2 = 0;
|
||||||
|
// countHighTemp
|
||||||
|
int cHTemp1 = 0;
|
||||||
|
int cHTemp2 = 0;
|
||||||
|
// loops to count temp before switching state
|
||||||
|
int cTemp = 5;
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// put your setup code here, to run once:
|
// put your setup code here, to run once:
|
||||||
pinMode(MOSFET1, OUTPUT);
|
pinMode(MOSFET1, OUTPUT);
|
||||||
pinMode(MOSFET2, OUTPUT);
|
pinMode(MOSFET2, OUTPUT);
|
||||||
|
|
||||||
|
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
sensors.begin();
|
sensors.begin();
|
||||||
|
|
||||||
|
// locate devices on the bus
|
||||||
|
Serial.println("Locating devices...");
|
||||||
|
Serial.print("Found ");
|
||||||
|
deviceCount = sensors.getDeviceCount();
|
||||||
|
Serial.print(deviceCount, DEC);
|
||||||
|
Serial.println(" devices.");
|
||||||
|
Serial.println("");
|
||||||
|
|
||||||
|
Serial.println("Printing addresses...");
|
||||||
|
for (int i = 0; i < deviceCount; i++)
|
||||||
|
{
|
||||||
|
Serial.print("Sensor ");
|
||||||
|
Serial.print(i+1);
|
||||||
|
Serial.print(" : ");
|
||||||
|
sensors.getAddress(Thermometer, i);
|
||||||
|
printAddress(Thermometer);
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println("");
|
||||||
|
Serial.print("MOSFET1 start temp: ");
|
||||||
|
Serial.print(HTemp1);
|
||||||
|
Serial.print("°C, stop temp: ");
|
||||||
|
Serial.print(LTemp1);
|
||||||
|
Serial.println("°C");
|
||||||
|
Serial.print("MOSFET2 start temp: ");
|
||||||
|
Serial.print(HTemp2);
|
||||||
|
Serial.print("°C, stop temp: ");
|
||||||
|
Serial.print(LTemp2);
|
||||||
|
Serial.println("°C");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
// put your main code here, to run repeatedly:
|
||||||
|
|
||||||
|
//if(Serial.available()>0) {
|
||||||
|
|
||||||
sensors.requestTemperatures();
|
sensors.requestTemperatures();
|
||||||
|
|
||||||
|
|
||||||
tempSensor1 = sensors.getTempC(addrSensor1);
|
tempSensor1 = sensors.getTempC(addrSensor1);
|
||||||
if(tempSensor1 > HTemp1) {
|
if(tempSensor1 > HTemp1) {
|
||||||
digitalWrite(MOSFET1, HIGH);
|
digitalWrite(MOSFET1, HIGH);
|
||||||
|
@ -69,16 +115,56 @@ void loop() {
|
||||||
fetState2 = 0;
|
fetState2 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Serial.print("Sens 1 ");
|
||||||
|
Serial.print("Celsius temperature: ");
|
||||||
|
// Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
|
||||||
|
Serial.print(sensors.getTempC(addrSensor1));
|
||||||
|
Serial.print(" - Fahrenheit temperature: ");
|
||||||
|
Serial.print(sensors.getTempF(addrSensor1));
|
||||||
|
Serial.print(" - MOSFET1 Sate: ");
|
||||||
|
Serial.println(fetState1);
|
||||||
|
|
||||||
|
Serial.print("Sens 2 ");
|
||||||
|
Serial.print("Celsius temperature: ");
|
||||||
|
// Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
|
||||||
|
Serial.print(sensors.getTempC(addrSensor2));
|
||||||
|
Serial.print(" - Fahrenheit temperature: ");
|
||||||
|
Serial.print(sensors.getTempF(addrSensor2));
|
||||||
|
Serial.print(" - MOSFET2 Sate: ");
|
||||||
|
Serial.println(fetState2);
|
||||||
|
*/
|
||||||
|
|
||||||
StaticJsonDocument<96> jsonOut;
|
StaticJsonDocument<96> jsonOut;
|
||||||
//jsonOut["sensor"] = "1";
|
//jsonOut["sensor"] = "1";
|
||||||
jsonOut[0]["temp"] = tempSensor1;
|
jsonOut["sensor1"]["temp"] = tempSensor1;
|
||||||
jsonOut[0]["state"] = fetState1;
|
jsonOut["sensor1"]["state"] = fetState1;
|
||||||
|
|
||||||
//jsonOut["sensor"] = "2";
|
//jsonOut["sensor"] = "2";
|
||||||
jsonOut[1]["temp"] = tempSensor2;
|
jsonOut["sensor2"]["temp"] = tempSensor2;
|
||||||
jsonOut[1]["state"] = fetState2;
|
jsonOut["sensor2"]["state"] = fetState2;
|
||||||
serializeJson(jsonOut, Serial);
|
serializeJson(jsonOut, Serial);
|
||||||
|
Serial.println();
|
||||||
delay(5000);
|
/*
|
||||||
|
digitalWrite(MOSFET, HIGH);
|
||||||
|
delay(2000);
|
||||||
|
digitalWrite(MOSFET, LOW);
|
||||||
|
delay(2000);
|
||||||
|
*/
|
||||||
|
delay(1000);
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void printAddress(DeviceAddress deviceAddress)
|
||||||
|
{
|
||||||
|
for (uint8_t i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
|
Serial.print("0x");
|
||||||
|
if (deviceAddress[i] < 0x10) Serial.print("0");
|
||||||
|
Serial.print(deviceAddress[i], HEX);
|
||||||
|
if (i < 7) Serial.print(", ");
|
||||||
|
}
|
||||||
|
Serial.println("");
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue