Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
Addition of System commands
Organizing MQTT-Topics
Fixing Basetopic issue
  • Loading branch information
cin3m committed Sep 11, 2023
1 parent 0ae00f6 commit bb9bcc2
Show file tree
Hide file tree
Showing 6 changed files with 305 additions and 52 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ Here are some examples how to use the MQTT interface:

| Topic | example JSON | Outcome |
|--------|----------------|---|
| visca/command/moveto | ```{x:400, y: 212, z: 0, focus: 420, cam: 0 }``` | Camera 0 moves to 400, 212, zooms all the way out, sets the focus to manual |
| visca/command/settings | ```{backlight: true, flip: true, mirror: true, mmdetect: true }``` | Camera 0 turns on backlight compensation, flips and mirrors the image and enables [EMFDP](# "external mechanical fuckery detection and prevention") |
| visca/command/picture | ```{wb:7,iris:-1}``` | Camera 1 sets whitebalance to 7 and enables auto exposure |
| visca/command/blinkenlights | ```{led: 1, mode: 2, cam: 0 }``` | Camera 0 turns on LED 1 in blinking mode. |
| visca/camera/command/moveto | ```{x:400, y: 212, z: 0, focus: 420, cam: 0 }``` | Camera 0 moves to 400, 212, zooms all the way out, sets the focus to manual |
| visca/camera/command/settings | ```{backlight: true, flip: true, mirror: true, mmdetect: true }``` | Camera 0 turns on backlight compensation, flips and mirrors the image and enables [EMFDP](# "external mechanical fuckery detection and prevention") |
| visca/camera/command/picture | ```{wb:7,iris:-1, cam: 1}``` | Camera 1 sets whitebalance to 7 and enables auto exposure |
| visca/camera/command/blinkenlights | ```{led: 1, mode: 2, cam: 0 }``` | Camera 0 turns on LED 1 in blinking mode. |
| visca/system/command/getConfig | ```{}``` | Returns the current MQTT configuration |
| visca/system/command/updateConfig | ```{"mqtt_server":"127.0.0.1","mqtt_port":"1883","mqtt_user":"test","mqtt_password":"","mqtt_basetopic":"Katzen/Futter"}``` | Update settings within the stored config.json on the microcontroller |
| visca/system/command/resetConfig | ```{"reset":true}``` | Factory defaults. |

## Hardware

Expand Down
8 changes: 4 additions & 4 deletions data/config.json_example
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"mqtt_server":"10.0.10.30",
"mqtt_server":"127.0.0.1",
"mqtt_port": "1883",
"mqtt_user":"iot",
"mqtt_password":"8ZsLNGYH7mzFLrMleUY1",
"mqtt_basetopic": "Community/VISCA/command/#"
"mqtt_user":"",
"mqtt_password":"",
"mqtt_basetopic": "VISCA"
}
7 changes: 4 additions & 3 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:d1_mini]
[env:d1_mini_jvpeek]
platform = espressif8266
board = d1_mini
framework = arduino
upload_protocol = espota
upload_port = 10.0.30.23
;upload_protocol = espota
;upload_port = 10.0.30.23
upload_port = COM10
monitor_speed = 9600
lib_deps =
ESP8266WiFi
Expand Down
164 changes: 163 additions & 1 deletion src/commands.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include <Arduino.h>
#include <camera.h>
#include <commands.h>
#include <ArduinoJson.h>
#include <FS.h>

PTZCam cams[NUM_CAMS];


/*VISCA Commands*/
VISCACommand makePackage(byte* payload, uint8_t length, uint8_t camNum) {
VISCACommand cmd;
uint8_t charCount = 0;
Expand Down Expand Up @@ -152,3 +154,163 @@ void requestEverything() {
}
}

/*System Commands*/
void handleCommands(char* topic, byte* payload, unsigned int length){
/*DynamicJsonBuffer response(1024);
JsonObject& responseObject = response.parseObject(payload);
if (!responseObject.containsKey("cam")) {
responseObject.set("cam", 0);
}
uint8_t camNum = responseObject["cam"].as<uint8_t>();
if (strcmp(topic, buildTopic("command/raw").c_str()) == 0) {
Serial.write(payload, length);
client.publish(buildTopic("status").c_str(),
("Kotze Daten " + String(length)).c_str());
}
if (strcmp(topic, buildTopic("command/blinkenlights").c_str()) == 0) {
VISCACommand command =
blinkenlights(responseObject["led"].as<uint8_t>(),
responseObject["mode"].as<uint8_t>(),
responseObject["cam"].as<uint8_t>());
Serial.write(command.payload, command.len);
}
if (strcmp(topic, buildTopic("command/settings").c_str()) == 0) {
if (responseObject.containsKey("backlight")) {
VISCACommand command =
backlight(responseObject["backlight"].as<bool>(),
responseObject["cam"].as<uint8_t>());
Serial.write(command.payload, command.len);
}
if (responseObject.containsKey("mirror")) {
VISCACommand command = mirror(responseObject["mirror"].as<bool>(),
responseObject["cam"].as<uint8_t>());
Serial.write(command.payload, command.len);
}
if (responseObject.containsKey("flip")) {
VISCACommand command = flip(responseObject["flip"].as<bool>(),
responseObject["cam"].as<uint8_t>());
Serial.write(command.payload, command.len);
}
if (responseObject.containsKey("mmdetect")) {
VISCACommand command =
mmdetect(responseObject["mmdetect"].as<bool>(),
responseObject["cam"].as<uint8_t>());
Serial.write(command.payload, command.len);
}
// ir_output, ir_cameracontrol
}
if (strcmp(topic, buildTopic("command/picture").c_str()) == 0) {
if (responseObject.containsKey("wb")) {
VISCACommand command = wb(responseObject["wb"].as<int>(),
responseObject["cam"].as<uint8_t>());
Serial.write(command.payload, command.len);
}
if (responseObject.containsKey("iris")) {
VISCACommand command = iris(responseObject["iris"].as<int>(),
responseObject["cam"].as<uint8_t>());
Serial.write(command.payload, command.len);
}
}
if (strcmp(topic, buildTopic("command/moveto").c_str()) == 0) {
if (responseObject.containsKey("x")) {
cams[responseObject["cam"].as<uint8_t>()].setX(
responseObject["x"].as<int>());
}
if (responseObject.containsKey("y")) {
cams[responseObject["cam"].as<uint8_t>()].setY(
responseObject["y"].as<int>());
}
if (responseObject.containsKey("z")) {
cams[responseObject["cam"].as<uint8_t>()].setZ(
responseObject["z"].as<int>());
}
if (responseObject.containsKey("focus")) {
cams[responseObject["cam"].as<uint8_t>()].setFocus(
responseObject["focus"].as<int>());
}
VISCACommand command = movement(responseObject["cam"].as<uint8_t>());
Serial.write(command.payload, command.len);
}
if (strcmp(topic, buildTopic("command/moveby").c_str()) == 0) {
if (!responseObject.containsKey("x")) {
responseObject.set("x", 0);
}
if (!responseObject.containsKey("y")) {
responseObject.set("y", 0);
}
VISCACommand command = relativeMovement(
responseObject["x"].as<int>(), responseObject["y"].as<int>(),
responseObject["cam"].as<uint8_t>());
Serial.write(command.payload, command.len);
client.publish(buildTopic("rawdata").c_str(), command.payload, command.len);
}
if (strcmp(topic, buildTopic("command/resetConfig").c_str()) == 0) {
if (responseObject.containsKey("reset")) {
Serial.println(String(responseObject["reset"]));
// && responseObject["reset"]
//ESP.eraseConfig();
}
}
if (strcmp(topic, buildTopic("command/updateConfig").c_str()) == 0) {
DynamicJsonBuffer jsonBuffer;
JsonObject& json = jsonBuffer.createObject();
File configFile = SPIFFS.open("/config.json", "w");
if (!configFile) {
debugPrintln("failed to open config file for writing");
} else {
if (responseObject.containsKey("mqtt_server")) {
json["mqtt_server"] = responseObject["mqtt_server"];
} else {
json["mqtt_server"] = mqtt_server;
}
if (responseObject.containsKey("mqtt_port")) {
json["mqtt_port"] = responseObject["mqtt_port"];
} else {
json["mqtt_port"] = mqtt_port;
}
if (responseObject.containsKey("mqtt_user")) {
json["mqtt_user"] = responseObject["mqtt_user"];
} else {
json["mqtt_user"] = mqtt_user;
}
if (responseObject.containsKey("mqtt_password")) {
json["mqtt_password"] = responseObject["mqtt_password"];
} else {
json["mqtt_password"] = mqtt_password;
}
if (responseObject.containsKey("mqtt_basetopic")) {
json["mqtt_basetopic"] = responseObject["mqtt_basetopic"];
} else {
json["mqtt_basetopic"] = mqtt_basetopic;
}
json.printTo(Serial);
json.printTo(configFile);
}
configFile.close();
delay(2000);
ESP.restart();
}*/
}
2 changes: 2 additions & 0 deletions src/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ void parseCommand(uint8_t* command, int length);
void requestEverything();
void handleSerial();

void handleCommands(char* topic, byte* payload, unsigned int length);

VISCACommand makePackage(byte* payload, uint8_t length, uint8_t camNum);
VISCACommand blinkenlights(uint8_t led = 0, uint8_t mode = 0, uint8_t cam = 0);
VISCACommand flip(bool setting = 0, uint8_t cam = 0);
Expand Down
Loading

0 comments on commit bb9bcc2

Please sign in to comment.