Smart home application with the T-Watch 2020 V3 from Lilygo
(EN google-translate)
(PL google-translate)
|
Turn on the light or power outlet:
{"id":1,"method":"setState","params":{"state":true}}
Turn off the light or unplug the power outlet:
{"id":1,"method":"setState","params":{"state":false}}
Set the lamp to a specific light temperature (here 3000 Kelvin) and a specific brightness (here 75 percent):
{"id":1,"method":"setPilot","params":{"temp":3000,"dimming":75}}
Set the red/green/blue ratio to a specific ratio and brightness:
{"id":1,"method":"setPilot","params":{"r":255,"g":0,"b":0,"dimming": 75}}
Status query for a device:
{"method":"getPilot","params":{}}
Code 0-1: UDP messages required for simple control tasks for products from Wiz.
|
12_Technikphilosophie/05_Fallstudien/01_Smart_Home
|
Preliminary test: Use of a Java/Processing sketch on a laptop/PC
Bild 0-1: Control the lamp from your PC.
|
import hypermedia.net.*;
UDP udp;
void setup()
{
udp = new UDP( this, 38899 );
udp.listen( true );
}
void draw()
{
size(200,200);
background(255,255,255);
}
boolean AN = true;
void keyPressed()
{
AN=!AN;
String message = "";
if(AN)
message = "{\"id\":1,\"method\":\"setState\",\"params\":{\"state\":true}}";
else
message = "{\"id\":1,\"method\":\"setState\",\"params\":{\"state\":false}}";
String ip = "10.42.0.255"; // the remote IP address
int port = 38899; // the destination port
message = message+";\n";
udp.send( message, ip, port );
}
void receive( byte[] data, String ip, int port )
{
data = subset(data, 0, data.length-2);
String message = new String( data );
println( "receive: \""+message+"\" from "+ip+" on port "+port );
}
Code 0-2: TWATCH_WIZ002_PC -- Java/Processing-Sketch zur Steuerung einer Smart Home Lampe per Tastendruck.
TWATCH_WIZ002_PC.zip -- Java/Processing sketch for controlling a smart home lamp at the touch of a button.
Using a T-WATCH V3 to control a smart home lamp
|
08_Archiv/06_Ing/01_Bauplan/04_Hotspot -- Instructions for setting up a hotspot on a Linux PC (Xubuntu).
05_esp32AV/01_Bauanleitung/01_Elektronik_und_Software/03_Videostream -- Instructions for setting up a hotspot with an Android smartphone.
|
Bild 0-2: Lamp off.
Bild 0-3: Lamp on.
TWATCH_PROC023_WIZ_LAMP_SMARTHOME.zip -- Project for Arduino IDE.
#include "twatch.h"
#include "variables.h"
#include "functions.h"
const char* hotspot = "hotspotK";
const char* password = "12345678";
int udpport = 38899;
bool ON=false;
const uint8_t messageON[] = "{\"id\":1,\"method\":\"setState\",\"params\":{\"state\":true}}";
const uint8_t messageOFF[] = "{\"id\":1,\"method\":\"setState\",\"params\":{\"state\":false}}";
char messageON_LEN[] = "{\"id\":1,\"method\":\"setState\",\"params\":{\"state\":true}}";
char messageOFF_LEN[] = "{\"id\":1,\"method\":\"setState\",\"params\":{\"state\":false}}";
char ip[] = "10.42.0.255";
IPAddress serverIP(10, 42, 0, 255); // Replace with the server's IP address
uint16_t serverPort = 38899; // Replace with the server's port
void setup()
{
setupTWATCH();
setupWIFI(hotspot,password,udpport);
setFont(1, 255,255,255, 0,0,0);
backlight(true);
}
void loop()
{
if(button())
{
if(!WIFIOKAY)
setupWIFI(hotspot,password,udpport);
ON=!ON;
if(ON)
{
udp.writeTo(messageON,strlen(messageON_LEN),serverIP,serverPort);
}
else
{
udp.writeTo(messageOFF,strlen(messageOFF_LEN),serverIP,serverPort);
}
}
clear();
cursor(0,0);
if(ON)
editor("LAMP ON!");
else
editor("LAMP OFF!");
delay(100);
}
Code 0-3: Main tab in project TWATCH_PROC023_WIZ_LAMP_SMARTHOME.