|
|
|
|
@ -11,13 +11,13 @@ that's been bundled out into its own FreeRTOS module (using the ESP IDF librarie
|
|
|
|
|
#include "bin_level.h"
|
|
|
|
|
#include "i2c_comms.h"
|
|
|
|
|
#include "io.h"
|
|
|
|
|
#include "wheel_speed.h"
|
|
|
|
|
#include "shaft_speed.h"
|
|
|
|
|
|
|
|
|
|
#define MOTOR_STATUS_UPDATE_PERIOD_MS 500
|
|
|
|
|
#define WHEEL_STATUS_UPDATE_PERIOD_MS 1000
|
|
|
|
|
#define BIN_STATUS_UPDATE_PERIOD_MS 3000 // also includes oil pressure sensor
|
|
|
|
|
#define PIPE_PRESSURE_UPDATE_PERIOD_MS 2000
|
|
|
|
|
#define HEARTBEAT_PERIOD_MS 1000
|
|
|
|
|
#define MOTOR_STATUS_UPDATE_PERIOD_MS 500
|
|
|
|
|
#define WHEEL_FAN_STATUS_UPDATE_PERIOD_MS 1000 // also includes oil pressure sensor
|
|
|
|
|
#define BIN_STATUS_UPDATE_PERIOD_MS 3000
|
|
|
|
|
#define PIPE_PRESSURE_UPDATE_PERIOD_MS 2000
|
|
|
|
|
#define HEARTBEAT_PERIOD_MS 1000
|
|
|
|
|
|
|
|
|
|
// Rate at which the current wheel speed will be used to update the desired roller speed
|
|
|
|
|
#define MOTOR_CONTROL_PERIOD_MS 100
|
|
|
|
|
@ -26,13 +26,13 @@ that's been bundled out into its own FreeRTOS module (using the ESP IDF librarie
|
|
|
|
|
|
|
|
|
|
#define POWER_NO_COMMS_TIMEOUT_MS 1000 * 60 * 5 // 5 minutes
|
|
|
|
|
|
|
|
|
|
EspMQTTClient mqtt_client("devtest", // Wifi SSID
|
|
|
|
|
"87usc6rs", // WiFi password
|
|
|
|
|
"10.9.2.101", // MQTT Broker server ip
|
|
|
|
|
"", // Can be omitted if not needed
|
|
|
|
|
"", // Can be omitted if not needed
|
|
|
|
|
"airseeder", // Client name that uniquely identify your device
|
|
|
|
|
1883 // The MQTT port, default to 1883. this line can be omitted
|
|
|
|
|
EspMQTTClient mqtt_client("RUT240_AC17", // Wifi SSID
|
|
|
|
|
"r8DBn0y4", // WiFi password
|
|
|
|
|
"192.168.1.1", // MQTT Broker server ip
|
|
|
|
|
"", // Can be omitted if not needed
|
|
|
|
|
"", // Can be omitted if not needed
|
|
|
|
|
"airseeder", // Client name that uniquely identify your device
|
|
|
|
|
1883 // The MQTT port, default to 1883. this line can be omitted
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
|
@ -67,6 +67,20 @@ void setup() {
|
|
|
|
|
Serial.println("Connected to MQTT broker");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Oil pressure switch is active when oil pressure is low (and rollers should not be driven).
|
|
|
|
|
bool get_oil_pressure_alarm() { return (digitalRead(GPIO_OIL_PRESSURE) == LOW); }
|
|
|
|
|
|
|
|
|
|
// Bin empty photointerrupters are active when grain is blocking them.
|
|
|
|
|
bool get_bin_empty(bin_id_t b_id) {
|
|
|
|
|
if (b_id == BIN_1) {
|
|
|
|
|
return (digitalRead(GPIO_BIN1_EMPTY) == HIGH);
|
|
|
|
|
}
|
|
|
|
|
if (b_id == BIN_2) {
|
|
|
|
|
return (digitalRead(GPIO_BIN2_EMPTY) == HIGH);
|
|
|
|
|
}
|
|
|
|
|
return (digitalRead(GPIO_BIN3_EMPTY) == HIGH);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char msg_buffer[100];
|
|
|
|
|
|
|
|
|
|
#define MAX_MSG_SEGMENTS 7
|
|
|
|
|
@ -324,28 +338,28 @@ void loop() {
|
|
|
|
|
mqtt_client.publish("airseeder/status/pipepressure", msg_buffer, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Periodically publish the wheel status
|
|
|
|
|
if (now - last_wheel_status > WHEEL_STATUS_UPDATE_PERIOD_MS) {
|
|
|
|
|
// Periodically publish the wheel and fan status
|
|
|
|
|
if (now - last_wheel_status > WHEEL_FAN_STATUS_UPDATE_PERIOD_MS) {
|
|
|
|
|
last_wheel_status = now;
|
|
|
|
|
sprintf(msg_buffer, "%lu %.2f %.2f", now, get_wheel_speed(), get_wheel_revs());
|
|
|
|
|
mqtt_client.publish("airseeder/status/wheel", msg_buffer, true);
|
|
|
|
|
|
|
|
|
|
sprintf(msg_buffer, "%lu %.2f %d", now, get_fan_speed(), get_oil_pressure_alarm());
|
|
|
|
|
mqtt_client.publish("airseeder/status/fan", msg_buffer, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// `airseeder/status/bin1` - `[timestamp] [empty] [distance]
|
|
|
|
|
// Periodically publish the bin status
|
|
|
|
|
if (now - last_bin_status > BIN_STATUS_UPDATE_PERIOD_MS) {
|
|
|
|
|
last_bin_status = now;
|
|
|
|
|
sprintf(msg_buffer, "%lu %d %.2f", now, digitalRead(GPIO_BIN1_EMPTY), get_bin_level(BIN_1));
|
|
|
|
|
sprintf(msg_buffer, "%lu %d %.2f", now, get_bin_empty(BIN_1), get_bin_level(BIN_1));
|
|
|
|
|
mqtt_client.publish("airseeder/status/bin1", msg_buffer, true);
|
|
|
|
|
|
|
|
|
|
sprintf(msg_buffer, "%lu %d %.2f", now, digitalRead(GPIO_BIN2_EMPTY), get_bin_level(BIN_2));
|
|
|
|
|
sprintf(msg_buffer, "%lu %d %.2f", now, get_bin_empty(BIN_2), get_bin_level(BIN_2));
|
|
|
|
|
mqtt_client.publish("airseeder/status/bin2", msg_buffer, true);
|
|
|
|
|
|
|
|
|
|
sprintf(msg_buffer, "%lu %d %.2f", now, digitalRead(GPIO_BIN3_EMPTY), get_bin_level(BIN_3));
|
|
|
|
|
sprintf(msg_buffer, "%lu %d %.2f", now, get_bin_empty(BIN_3), get_bin_level(BIN_3));
|
|
|
|
|
mqtt_client.publish("airseeder/status/bin3", msg_buffer, true);
|
|
|
|
|
|
|
|
|
|
sprintf(msg_buffer, "%lu %d", now, digitalRead(GPIO_OIL_PRESSURE));
|
|
|
|
|
mqtt_client.publish("airseeder/status/oilpressure", msg_buffer, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Periodically publish the heartbeat
|
|
|
|
|
@ -409,6 +423,12 @@ void loop() {
|
|
|
|
|
m_ctrl[r_id].enabled = false;
|
|
|
|
|
m_ctrl[r_id].desired_speed = 0.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If we don't have oil pressure yet, do not actually drive motors (but still allow speed setting and mode
|
|
|
|
|
// changes)
|
|
|
|
|
if (get_oil_pressure_alarm()) {
|
|
|
|
|
m_ctrl[r_id].enabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
motor_control_group.motor_1 = m_ctrl[0];
|
|
|
|
|
motor_control_group.motor_2 = m_ctrl[1];
|
|
|
|
|
|