Compare commits
5 Commits
ab53eb2ee6
...
6741f77615
Author | SHA1 | Date | |
---|---|---|---|
![]() |
6741f77615 | ||
![]() |
a98acc9060 | ||
![]() |
c619488738 | ||
![]() |
a17eb70ce0 | ||
![]() |
8525da4004 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +0,0 @@
|
||||
STM32_CONTROL/.vscode
|
||||
STM32_CONTROL/.pio
|
6
ARDUINO_NANO_CONTROLL/.gitignore
vendored
Normal file
6
ARDUINO_NANO_CONTROLL/.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
.pio
|
||||
.vscode/.browse.c_cpp.db*
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
.vscode/ipch
|
||||
.vscode
|
37
ARDUINO_NANO_CONTROLL/include/README
Normal file
37
ARDUINO_NANO_CONTROLL/include/README
Normal file
@ -0,0 +1,37 @@
|
||||
|
||||
This directory is intended for project header files.
|
||||
|
||||
A header file is a file containing C declarations and macro definitions
|
||||
to be shared between several project source files. You request the use of a
|
||||
header file in your project source file (C, C++, etc) located in `src` folder
|
||||
by including it, with the C preprocessing directive `#include'.
|
||||
|
||||
```src/main.c
|
||||
|
||||
#include "header.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
Including a header file produces the same results as copying the header file
|
||||
into each source file that needs it. Such copying would be time-consuming
|
||||
and error-prone. With a header file, the related declarations appear
|
||||
in only one place. If they need to be changed, they can be changed in one
|
||||
place, and programs that include the header file will automatically use the
|
||||
new version when next recompiled. The header file eliminates the labor of
|
||||
finding and changing all the copies as well as the risk that a failure to
|
||||
find one copy will result in inconsistencies within a program.
|
||||
|
||||
In C, the convention is to give header files names that end with `.h'.
|
||||
|
||||
Read more about using header files in official GCC documentation:
|
||||
|
||||
* Include Syntax
|
||||
* Include Operation
|
||||
* Once-Only Headers
|
||||
* Computed Includes
|
||||
|
||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
46
ARDUINO_NANO_CONTROLL/lib/README
Normal file
46
ARDUINO_NANO_CONTROLL/lib/README
Normal file
@ -0,0 +1,46 @@
|
||||
|
||||
This directory is intended for project specific (private) libraries.
|
||||
PlatformIO will compile them to static libraries and link into the executable file.
|
||||
|
||||
The source code of each library should be placed in a separate directory
|
||||
("lib/your_library_name/[Code]").
|
||||
|
||||
For example, see the structure of the following example libraries `Foo` and `Bar`:
|
||||
|
||||
|--lib
|
||||
| |
|
||||
| |--Bar
|
||||
| | |--docs
|
||||
| | |--examples
|
||||
| | |--src
|
||||
| | |- Bar.c
|
||||
| | |- Bar.h
|
||||
| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||
| |
|
||||
| |--Foo
|
||||
| | |- Foo.c
|
||||
| | |- Foo.h
|
||||
| |
|
||||
| |- README --> THIS FILE
|
||||
|
|
||||
|- platformio.ini
|
||||
|--src
|
||||
|- main.c
|
||||
|
||||
Example contents of `src/main.c` using Foo and Bar:
|
||||
```
|
||||
#include <Foo.h>
|
||||
#include <Bar.h>
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
The PlatformIO Library Dependency Finder will find automatically dependent
|
||||
libraries by scanning project source files.
|
||||
|
||||
More information about PlatformIO Library Dependency Finder
|
||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
18
ARDUINO_NANO_CONTROLL/platformio.ini
Normal file
18
ARDUINO_NANO_CONTROLL/platformio.ini
Normal file
@ -0,0 +1,18 @@
|
||||
; PlatformIO Project Configuration File
|
||||
;
|
||||
; Build options: build flags, source filter
|
||||
; Upload options: custom upload port, speed and extra flags
|
||||
; Library options: dependencies, extra library storages
|
||||
; Advanced options: extra scripting
|
||||
;
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:nanoatmega328]
|
||||
platform = atmelavr
|
||||
board = nanoatmega328
|
||||
framework = arduino
|
||||
lib_deps =
|
||||
adafruit/DHT sensor library@^1.4.6
|
||||
featherfly/SoftwareSerial@^1.0
|
||||
board_build.mcu = atmega328p
|
285
ARDUINO_NANO_CONTROLL/src/main.cpp
Normal file
285
ARDUINO_NANO_CONTROLL/src/main.cpp
Normal file
@ -0,0 +1,285 @@
|
||||
#include <Arduino.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include <DHT.h>
|
||||
#include <DHT_U.h>
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// DHT PreConfiguration
|
||||
#define DHTPIN 4 // Digital pin connected to the DHT sensor
|
||||
//#define DHTPIN PB0
|
||||
// Pin 15 can work but DHT must be disconnected during program upload.
|
||||
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
|
||||
// -------------------------------------------------------------
|
||||
// Initialize DHT sensor.
|
||||
// Note that older versions of this library took an optional third parameter to
|
||||
// tweak the timings for faster processors. This parameter is no longer needed
|
||||
// as the current DHT reading algorithm adjusts itself to work on faster procs.
|
||||
DHT dht(DHTPIN, DHTTYPE);
|
||||
|
||||
|
||||
// VARS
|
||||
const int MD1200BAUDS = 38400; // From what I've read it is always 38400
|
||||
//const int EPYSLEEPY = 600000; / 10 minutes
|
||||
const long EPYSLEEPY = 300000; // 5 minutes
|
||||
//const int EPYSLEEPY = 150000; // 2,5 minutes
|
||||
|
||||
#define RX_PIN 3
|
||||
#define TX_PIN 2
|
||||
SoftwareSerial MDSerial(RX_PIN, TX_PIN); // Goes up to 115200 bauds
|
||||
|
||||
// declarations
|
||||
int getTemp();
|
||||
int setFanTrsh(int);
|
||||
float dhtRead();
|
||||
|
||||
void setup() {
|
||||
// Setup connection to MD1200
|
||||
// Serial because we're using RX/TX pins
|
||||
MDSerial.begin(MD1200BAUDS);
|
||||
|
||||
// Just debug
|
||||
Serial.begin(9600);
|
||||
|
||||
dht.begin();
|
||||
|
||||
Serial.println("setup end");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
Serial.println("Loop start");
|
||||
|
||||
int fanPercnt = getTemp();
|
||||
|
||||
if (fanPercnt < 10) {
|
||||
setFanTrsh(fanPercnt);
|
||||
}
|
||||
|
||||
/*
|
||||
check temperature and
|
||||
set fan speed every X minutes
|
||||
*/
|
||||
delay(EPYSLEEPY);
|
||||
|
||||
}
|
||||
|
||||
// Get current temperature
|
||||
int getTemp() {
|
||||
Serial.println("getTemp start");
|
||||
|
||||
int bp1 = 0;
|
||||
int bp2 = 0;
|
||||
// int exp0 = 0;
|
||||
// int exp1 = 0;
|
||||
// int simm0 = 0;
|
||||
// int simm1 = 0;
|
||||
String MD1200output;
|
||||
|
||||
MDSerial.println("_temp_rd");
|
||||
|
||||
// wait for MD1200 to answer
|
||||
delay(30);
|
||||
Serial.println("start parsing temperature start");
|
||||
|
||||
while (MDSerial.available()) {
|
||||
MD1200output = MDSerial.readStringUntil('\n');
|
||||
|
||||
// Check backplane 1
|
||||
if (MD1200output.startsWith("BP_1")) {
|
||||
// check index number of =
|
||||
int eq = MD1200output.indexOf('=');
|
||||
// check index number of c
|
||||
int c = MD1200output.indexOf('c');
|
||||
// check if both exists
|
||||
if (eq != -1 && c != -1) {
|
||||
/*
|
||||
take value between "= " and "c".
|
||||
NOTICE that eq + 1 is there because in
|
||||
"BP_1[2] = 25c" there is a space between = and 25.
|
||||
*/
|
||||
bp1 = MD1200output.substring(eq + 1, c).toInt();
|
||||
Serial.println("Backplane 1 " + String(bp1));
|
||||
}
|
||||
}
|
||||
|
||||
// Check backplane 2
|
||||
if (MD1200output.startsWith("BP_2")) {
|
||||
int eq = MD1200output.indexOf('=');
|
||||
int c = MD1200output.indexOf('c');
|
||||
if (eq != -1 && c != -1) {
|
||||
bp2 = MD1200output.substring(eq + 1, c).toInt();
|
||||
Serial.println("Backplane 2 " + String(bp2));
|
||||
}
|
||||
}
|
||||
|
||||
// Uncomment if you want to also get temperature for expanders
|
||||
/*
|
||||
|
||||
// Check expander 0
|
||||
if (MD1200output.startsWith("EXP0")) {
|
||||
int eq = MD1200output.indexOf('=');
|
||||
int c = MD1200output.indexOf('c');
|
||||
if (eq != -1 && c != -1) {
|
||||
exp0 = MD1200output.substring(eq + 1, c).toInt();
|
||||
}
|
||||
}
|
||||
|
||||
// Check expander 1
|
||||
if (MD1200output.startsWith("EXP1")) {
|
||||
int eq = MD1200output.indexOf('=');
|
||||
int c = MD1200output.indexOf('c');
|
||||
if (eq != -1 && c != -1) {
|
||||
exp1 = MD1200output.substring(eq + 1, c).toInt();
|
||||
}
|
||||
}
|
||||
|
||||
// Check controller 0
|
||||
if (MD1200output.startsWith("SIM0")) {
|
||||
int eq = MD1200output.indexOf('=');
|
||||
int c = MD1200output.indexOf('c');
|
||||
if (eq != -1 && c != -1) {
|
||||
simm0 = MD1200output.substring(eq + 1, c).toInt();
|
||||
}
|
||||
}
|
||||
|
||||
// Check controller 1
|
||||
if (MD1200output.startsWith("SIM1")) {
|
||||
int eq = MD1200output.indexOf('=');
|
||||
int c = MD1200output.indexOf('c');
|
||||
if (eq != -1 && c != -1) {
|
||||
simm1 = MD1200output.substring(eq + 1, c).toInt();
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
// Stop when prompt returns
|
||||
if (MD1200output.endsWith(">")) {
|
||||
Serial.println("stopping temp reading");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Do (BP_1 + BP_2) / 2 to get the average of backplane
|
||||
if (bp1 != -1 && bp2 != -1) {
|
||||
int bpAvg = (bp1 + bp2) / 2;
|
||||
|
||||
Serial.println("Average temp is " + String(bpAvg));
|
||||
|
||||
// define default
|
||||
int outPrcntg = 21;
|
||||
|
||||
// check external sensor temp
|
||||
int ownReadTemp = int(dhtRead());
|
||||
|
||||
|
||||
Serial.println("Checking DHT temp");
|
||||
if (ownReadTemp <= 35) {
|
||||
return 40;
|
||||
}
|
||||
|
||||
// a
|
||||
switch (bpAvg) {
|
||||
case 23:
|
||||
outPrcntg = 21;
|
||||
break;
|
||||
/*
|
||||
Minimum is 21 (akhsually 20)
|
||||
BUT
|
||||
https://forums.servethehome.com/index.php?threads/fun-with-an-md1200-md1220-sc200-sc220.27487/
|
||||
*/
|
||||
case 25:
|
||||
outPrcntg = 23;
|
||||
break;
|
||||
case 27:
|
||||
outPrcntg = 24;
|
||||
break;
|
||||
case 29:
|
||||
outPrcntg = 26;
|
||||
break;
|
||||
case 31:
|
||||
outPrcntg = 27;
|
||||
break;
|
||||
case 33:
|
||||
outPrcntg = 30;
|
||||
break;
|
||||
case 35:
|
||||
outPrcntg = 34;
|
||||
break;
|
||||
case 37:
|
||||
outPrcntg = 38;
|
||||
break;
|
||||
/*
|
||||
I don't wan't to become deaf so max is 40.
|
||||
*/
|
||||
|
||||
default:
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
Serial.println("Returnning " + String(outPrcntg) + " %");
|
||||
return outPrcntg;
|
||||
|
||||
} else {
|
||||
return -1; // failed to read temp
|
||||
}
|
||||
|
||||
/*
|
||||
BP_1[2] - Back plane, maybe left
|
||||
BP_2[3] - Back plane, maybe right
|
||||
SIM0[0] - Controller A
|
||||
SIM1[1] - Controller B
|
||||
EXP0[4] - Expander 0
|
||||
EXP1[5] - Expander 1
|
||||
|
||||
AVG - average of all sensors
|
||||
*/
|
||||
}
|
||||
|
||||
// take percentage as int and set it.
|
||||
int setFanTrsh(int fanTrshInp) {
|
||||
|
||||
Serial.println("Setting fan speed");
|
||||
String outputStatement = "set_speed " + String(fanTrshInp);
|
||||
|
||||
// MDSerial.println("Sending " + outputStatement + " to MD1200");
|
||||
|
||||
if (MDSerial.println(outputStatement)) {
|
||||
Serial.println("Setting fan speed success");
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
Serial.println("Setting fan speed unsuccess");
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
float dhtRead() {
|
||||
// Reading temperature or humidity takes about 250 milliseconds!
|
||||
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
|
||||
// float humidt = dht.readHumidity();
|
||||
// Read temperature as Celsius (the default)
|
||||
float tempr = dht.readTemperature();
|
||||
// Read temperature as Fahrenheit (isFahrenheit = true)
|
||||
// f = dht.readTemperature(true);
|
||||
|
||||
// Check if any reads failed and exit early (to try again).
|
||||
// if (isnan(humidt) || isnan(tempr))
|
||||
if (isnan(tempr))
|
||||
{
|
||||
// MDSerial.println("Failed to read from DHT sensor!");
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
return tempr;
|
||||
}
|
||||
|
||||
// Compute heat index in Fahrenheit (the default)
|
||||
// hif = dht.computeHeatIndex(f, h);
|
||||
// Compute heat index in Celsius (isFahreheit = false)
|
||||
// hicc = dht.computeHeatIndex(tempr, humidt, false);
|
||||
|
||||
}
|
11
ARDUINO_NANO_CONTROLL/test/README
Normal file
11
ARDUINO_NANO_CONTROLL/test/README
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
This directory is intended for PlatformIO Test Runner and project tests.
|
||||
|
||||
Unit Testing is a software testing method by which individual units of
|
||||
source code, sets of one or more MCU program modules together with associated
|
||||
control data, usage procedures, and operating procedures, are tested to
|
||||
determine whether they are fit for use. Unit testing finds problems early
|
||||
in the development cycle.
|
||||
|
||||
More information about PlatformIO Unit Testing:
|
||||
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
|
1
PC_CONTROL_CODE/.gitignore
vendored
Normal file
1
PC_CONTROL_CODE/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
testing
|
29
PC_CONTROL_CODE/main.dht22.py
Normal file
29
PC_CONTROL_CODE/main.dht22.py
Normal file
@ -0,0 +1,29 @@
|
||||
import time
|
||||
import board
|
||||
import adafruit_dht
|
||||
|
||||
# https://randomnerdtutorials.com/raspberry-pi-dht11-dht22-python/
|
||||
|
||||
# Sensor data pin is connected to GPIO 4
|
||||
sensor = adafruit_dht.DHT22(board.D4)
|
||||
# Uncomment for DHT11
|
||||
#sensor = adafruit_dht.DHT11(board.D4)
|
||||
|
||||
while True:
|
||||
try:
|
||||
# Print the values to the serial port
|
||||
temperature_c = sensor.temperature
|
||||
temperature_f = temperature_c * (9 / 5) + 32
|
||||
humidity = sensor.humidity
|
||||
print("Temp={0:0.1f}ºC, Temp={1:0.1f}ºF, Humidity={2:0.1f}%".format(temperature_c, temperature_f, humidity))
|
||||
|
||||
except RuntimeError as error:
|
||||
# Errors happen fairly often, DHT's are hard to read, just keep going
|
||||
print(error.args[0])
|
||||
time.sleep(2.0)
|
||||
continue
|
||||
except Exception as error:
|
||||
sensor.exit()
|
||||
raise error
|
||||
|
||||
time.sleep(3.0)
|
67
PC_CONTROL_CODE/main.py
Normal file
67
PC_CONTROL_CODE/main.py
Normal file
@ -0,0 +1,67 @@
|
||||
import serial, time
|
||||
|
||||
# CONST
|
||||
MD1200BAUD = 38400
|
||||
SERIALADAPTER = "/dev/ttyUSB0" # In Windows it would be something like COM3
|
||||
|
||||
# init
|
||||
MDserial = serial.Serial(
|
||||
port=SERIALADAPTER,\
|
||||
baudrate=MD1200BAUD,\
|
||||
parity=serial.PARITY_NONE,\
|
||||
stopbits=serial.STOPBITS_ONE,\
|
||||
bytesize=serial.EIGHTBITS,\
|
||||
timeout=1)
|
||||
|
||||
|
||||
# Check if UART is used
|
||||
# Not neede because when defining MDserial it gets automatically opened
|
||||
# try:
|
||||
# MDserial.open()
|
||||
# except serial.serialutil.SerialException:
|
||||
# # MDserial.close()
|
||||
# # MDserial.open()
|
||||
# print("Port allready opened.\nTry closing it first")
|
||||
|
||||
|
||||
def getTemp():
|
||||
print()
|
||||
|
||||
def setSpeed():
|
||||
print()
|
||||
|
||||
while True:
|
||||
MDreturning = MDserial.read_until(" >").decode()
|
||||
|
||||
# sleep(50)
|
||||
MDfanspeed = getTemp(MDreturning)
|
||||
|
||||
setSpeedrcode = setSpeed()
|
||||
|
||||
if setSpeedrcode == 0:
|
||||
continue
|
||||
elif setSpeedrcode == -1:
|
||||
continue
|
||||
else:
|
||||
print("o nyo")
|
||||
exit()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# https://stackoverflow.com/questions/52578122/not-able-to-send-the-enter-command-on-pyserial
|
||||
# MDserial.write("_temp_rd\n\r".encode())
|
||||
|
||||
# getTemp()
|
||||
# print(MDserial.read_until(" >"))
|
||||
|
||||
# fanprct = 23
|
||||
|
||||
# MDserial.write(f"set_speed {fanprct}\n\r".encode())
|
||||
|
||||
|
||||
|
||||
|
||||
# print("closing port")
|
||||
# MDserial.close()
|
1
PC_CONTROL_CODE/requirements.txt
Normal file
1
PC_CONTROL_CODE/requirements.txt
Normal file
@ -0,0 +1 @@
|
||||
pySerial == 3.5
|
27
PC_CONTROL_CODE/systemd/MD1200Fans.example.service
Normal file
27
PC_CONTROL_CODE/systemd/MD1200Fans.example.service
Normal file
@ -0,0 +1,27 @@
|
||||
[Unit]
|
||||
Description=Netflow to InfluxDB script
|
||||
After=multi-user.target network.target network-online.target
|
||||
# Place in /etc/systemd/system/
|
||||
|
||||
[Service]
|
||||
User=yuru
|
||||
Group=yuru
|
||||
Type=simple
|
||||
Restart=on-failure
|
||||
# EnvironmentFile=/etc/NetFlux/netflow.env
|
||||
# User=myuser
|
||||
WorkingDirectory=/etc/NetFlux/HQ/
|
||||
ExecStart=/etc/NetFlux/HQ/venv/bin/python3 /etc/NetFlux/HQ/HQnetflow.py --serve-in-foreground
|
||||
|
||||
#StandardInput=tty-force
|
||||
|
||||
# Log file will be create if it doesn't exist
|
||||
StandardOutput=append:/var/log/HQNetFlowInflux.log
|
||||
StandardError=append:/var/log/HQNetFlowInflux.errlog
|
||||
|
||||
# StandardOutput=syslog
|
||||
# StandardError=syslog
|
||||
# SyslogIdentifier=NetFlowInflux
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
26
PC_CONTROL_CODE/systemd/MD1200Fans.service
Normal file
26
PC_CONTROL_CODE/systemd/MD1200Fans.service
Normal file
@ -0,0 +1,26 @@
|
||||
[Unit]
|
||||
Description=Netflow to InfluxDB script
|
||||
After=multi-user.target network.target network-online.target
|
||||
# Place in /etc/systemd/system/
|
||||
|
||||
[Service]
|
||||
User=<CHANGE>
|
||||
Group=<CHANGE>
|
||||
Type=simple
|
||||
Restart=on-failure
|
||||
# EnvironmentFile=/etc/NetFlux/netflow.env
|
||||
# User=myuser
|
||||
WorkingDirectory=/dir/to/script/
|
||||
ExecStart=/dir/to/script'sVENV/venv/bin/python3 /dir/to/script/NetFlowCollect.py --serve-in-foreground
|
||||
#StandardInput=tty-force
|
||||
|
||||
# Log file will be create if it doesn't exist
|
||||
StandardOutput=append:/var/log/NetFlowCollect.log
|
||||
StandardError=append:/var/log/NetFlowCollect.errlog
|
||||
|
||||
# StandardOutput=syslog
|
||||
# StandardError=syslog
|
||||
# SyslogIdentifier=NetFlowInflux
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
8
PC_CONTROL_CODE/systemd/README.md
Normal file
8
PC_CONTROL_CODE/systemd/README.md
Normal file
@ -0,0 +1,8 @@
|
||||
# What you need to prepare
|
||||
|
||||
virtual enviroment in python with installed packages
|
||||
|
||||
python script and InfluxDB
|
||||
|
||||
## Change stuff
|
||||
In .service file change everything that has <SOMETHIN_LIKE_THIS> and /path/to/dir
|
10
STM32_CONTROL/.vscode/extensions.json
vendored
Normal file
10
STM32_CONTROL/.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||
// for the documentation about the extensions.json format
|
||||
"recommendations": [
|
||||
"platformio.platformio-ide"
|
||||
],
|
||||
"unwantedRecommendations": [
|
||||
"ms-vscode.cpptools-extension-pack"
|
||||
]
|
||||
}
|
@ -13,6 +13,8 @@ platform = ststm32
|
||||
board = genericSTM32F103C6
|
||||
framework = arduino
|
||||
lib_deps = adafruit/DHT sensor library@^1.4.6
|
||||
debug_tool = stlink
|
||||
upload_protocol = stlink
|
||||
; Enable RX and TX 3
|
||||
; build_flags = -D SERIAL_USB -D ENABLE_HWSERIAL3
|
||||
; build_flags = -D SERIAL_USB -D ENABLE_HWSERIAL1 -D ENABLE_HWSERIAL2
|
||||
; build_flags = -DENABLE_HWSERIAL1
|
22
STM32_CONTROL/src/test.cpp
Normal file
22
STM32_CONTROL/src/test.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
|
||||
// UART2 (PA3 = RX, PA2 = TX)
|
||||
HardwareSerial mdSerial(PA10, PA9);
|
||||
// HardwareSerial sigma(PA9, )
|
||||
|
||||
|
||||
|
||||
void setup() {
|
||||
|
||||
mdSerial.begin(38400);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
mdSerial.write("skibidi");
|
||||
|
||||
delay(5000); // wait before next loop
|
||||
}
|
@ -6,7 +6,9 @@ const int MD1200BAUDS = 38400; // From what I've read it is always 38400
|
||||
//const int EPYSLEEPY = 600000; / 10 minutes
|
||||
const int EPYSLEEPY = 300000; // 5 minutes
|
||||
//const int EPYSLEEPY = 150000; // 2,5 minutes
|
||||
HardwareSerial Serial1(31, 30);
|
||||
HardwareSerial MDSerial(PA3, PA2); // Rx Tx
|
||||
HardwareSerial DeBug(PA10, PA9); // Rx Tx
|
||||
// HardwareSerial DeBug(USART1); // use USART1
|
||||
|
||||
// declarations
|
||||
int getTemp();
|
||||
@ -14,19 +16,23 @@ int setFanTrsh(int);
|
||||
|
||||
void setup() {
|
||||
// Setup connection to MD1200
|
||||
// Serial1 because we're using RX/TX pins
|
||||
Serial1.begin(MD1200BAUDS);
|
||||
// MDSerial because we're using RX/TX pins
|
||||
MDSerial.begin(MD1200BAUDS);
|
||||
|
||||
// Just debug
|
||||
Serial.begin(9600);
|
||||
Serial.print("skibidi");
|
||||
DeBug.begin(9600);
|
||||
DeBug.println("skibidi");
|
||||
delay(15000);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
DeBug.println("Starting loop");
|
||||
|
||||
int fanPercnt = getTemp();
|
||||
|
||||
if (fanPercnt < 10) {
|
||||
DeBug.println("Executing setFanTrsh");
|
||||
setFanTrsh(fanPercnt);
|
||||
}
|
||||
|
||||
@ -35,11 +41,12 @@ void loop() {
|
||||
set fan speed every X minutes
|
||||
*/
|
||||
delay(EPYSLEEPY);
|
||||
|
||||
DeBug.println("Ending loop");
|
||||
}
|
||||
|
||||
// Get current temperature
|
||||
int getTemp() {
|
||||
DeBug.println("Getting Temperature");
|
||||
|
||||
int bp1 = 0;
|
||||
int bp2 = 0;
|
||||
@ -49,13 +56,13 @@ int getTemp() {
|
||||
int simm1 = 0;
|
||||
String MD1200output;
|
||||
|
||||
Serial1.println("_temp_rd");
|
||||
MDSerial.println("_temp_rd");
|
||||
|
||||
// wait for MD1200 to answer
|
||||
delay(30);
|
||||
|
||||
while (Serial1.available()) {
|
||||
MD1200output = Serial1.readStringUntil('\n');
|
||||
DeBug.println("getTemp logic start");
|
||||
while (MDSerial.available()) {
|
||||
MD1200output = MDSerial.readStringUntil('\n');
|
||||
|
||||
// Check backplane 1
|
||||
if (MD1200output.startsWith("BP_1")) {
|
||||
@ -126,6 +133,7 @@ int getTemp() {
|
||||
|
||||
// Stop when prompt returns
|
||||
if (MD1200output.endsWith(">")) {
|
||||
DeBug.println("getTemp got all temp info");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -138,6 +146,7 @@ int getTemp() {
|
||||
int outPrcntg = 21;
|
||||
|
||||
// a
|
||||
DeBug.println("getTemp choosing fan speed");
|
||||
switch (bpAvg) {
|
||||
case 23:
|
||||
outPrcntg = 21;
|
||||
@ -170,8 +179,11 @@ int getTemp() {
|
||||
|
||||
default:
|
||||
return -1;
|
||||
DeBug.println("getTemp error returning -1");
|
||||
|
||||
|
||||
}
|
||||
DeBug.println("getTemp return " + String(outPrcntg));
|
||||
|
||||
return outPrcntg;
|
||||
|
||||
@ -195,9 +207,9 @@ int getTemp() {
|
||||
int setFanTrsh(int fanTrshInp) {
|
||||
String outputStatement = "set_speed " + String(fanTrshInp);
|
||||
|
||||
Serial.println("Sending " + outputStatement + " to MD1200");
|
||||
DeBug.println("Sending " + outputStatement + " to MD1200");
|
||||
|
||||
if (Serial1.println(outputStatement)) {
|
||||
if (MDSerial.println(outputStatement)) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
@ -2,6 +2,7 @@
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include <DHT.h>
|
||||
#include <DHT_U.h>
|
||||
#include <HardwareSerial.h>
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// DHT PreConfiguration
|
||||
@ -22,6 +23,7 @@ const int MD1200BAUDS = 38400; // From what I've read it is always 38400
|
||||
//const int EPYSLEEPY = 600000; / 10 minutes
|
||||
const int EPYSLEEPY = 300000; // 5 minutes
|
||||
//const int EPYSLEEPY = 150000; // 2,5 minutes
|
||||
HardwareSerial MDSerial(PA3, PA2); // Rx Tx
|
||||
|
||||
// declarations
|
||||
int getTemp();
|
||||
@ -30,8 +32,8 @@ float dhtRead();
|
||||
|
||||
void setup() {
|
||||
// Setup connection to MD1200
|
||||
// Serial1 because we're using RX/TX pins
|
||||
Serial1.begin(MD1200BAUDS);
|
||||
// MDSerial because we're using RX/TX pins
|
||||
MDSerial.begin(MD1200BAUDS);
|
||||
|
||||
// Just debug
|
||||
Serial.begin(9600);
|
||||
@ -66,13 +68,13 @@ int getTemp() {
|
||||
int simm1 = 0;
|
||||
String MD1200output;
|
||||
|
||||
Serial1.println("_temp_rd");
|
||||
MDSerial.println("_temp_rd");
|
||||
|
||||
// wait for MD1200 to answer
|
||||
delay(30);
|
||||
|
||||
while (Serial1.available()) {
|
||||
MD1200output = Serial1.readStringUntil('\n');
|
||||
while (MDSerial.available()) {
|
||||
MD1200output = MDSerial.readStringUntil('\n');
|
||||
|
||||
// Check backplane 1
|
||||
if (MD1200output.startsWith("BP_1")) {
|
||||
@ -221,7 +223,7 @@ int setFanTrsh(int fanTrshInp) {
|
||||
|
||||
Serial.println("Sending " + outputStatement + " to MD1200");
|
||||
|
||||
if (Serial1.println(outputStatement)) {
|
||||
if (MDSerial.println(outputStatement)) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user