arduino-fridge-powercontrol/main/main.ino

88 lines
2.1 KiB
Arduino
Raw Normal View History

2023-08-01 23:38:12 +02:00
2023-08-02 01:04:39 +02:00
#include "ArduinoJson.h"
2023-08-01 23:38:12 +02:00
int analogPin = 3;
int data = 0;
char userInput;
2023-08-02 01:35:46 +02:00
char* commandVer;
2023-08-01 23:38:12 +02:00
2023-08-02 01:04:39 +02:00
2023-08-01 23:38:12 +02:00
void setup() {
// put your setup code here, to run once:
pinMode(LED_BUILTIN, OUTPUT);
2023-08-02 01:04:39 +02:00
2023-08-01 23:38:12 +02:00
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
2023-08-02 01:04:39 +02:00
if(Serial.available()>0) {
//userInput = Serial.read();
// String input;
2023-08-02 01:35:46 +02:00
//{ "command": "switch", "arg": "one", "state": "off", "ver":"1690931931"}
StaticJsonDocument<96> jsonin;
2023-08-02 01:04:39 +02:00
2023-08-02 01:35:46 +02:00
DeserializationError error = deserializeJson(jsonin, Serial);
2023-08-02 01:04:39 +02:00
if (error) {
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.f_str());
return;
}
2023-08-02 01:35:46 +02:00
const char* command = jsonin["command"]; // "switch"
const char* arg = jsonin["arg"]; // "one"
const char* state = jsonin["state"]; // "off"
const char* ver = jsonin["ver"]; // "1690931931"
2023-08-02 01:04:39 +02:00
2023-08-02 01:35:46 +02:00
StaticJsonDocument<96> jsonout;
jsonout["command"] = "lol";
jsonout["arg"] = "rofl";
jsonout["state"] = "on";
jsonout["ver"] = "1690931337";
serializeJson(jsonout, Serial);
/*
2023-08-02 01:04:39 +02:00
Serial.print(command);
Serial.print(" - ");
Serial.print(arg);
Serial.print(" - ");
2023-08-02 01:35:46 +02:00
Serial.print(state);
Serial.print(" - ");
Serial.println(ver);
2023-08-01 23:38:12 +02:00
if(userInput == 'g') {
data = analogRead(analogPin);
2023-08-02 01:35:46 +02:00
*/
2023-08-01 23:38:12 +02:00
/*
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(200); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(200);
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(200); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(200);
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(200); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(200);
2023-08-02 01:35:46 +02:00
2023-08-02 01:04:39 +02:00
//delay(2000);
2023-08-01 23:38:12 +02:00
Serial.println(data);
2023-08-02 01:35:46 +02:00
*/
//}
2023-08-01 23:38:12 +02:00
}
}