kramann.info
© Guido Kramann

Login: Passwort:










kramann.info
© Guido Kramann

Login: Passwort:




Smart home application with the T-Watch 2020 V3 from Lilygo

(EN google-translate)

(PL google-translate)

  • One method of connecting smart home modules to each other is to use a local WiFi network with the UDP protocol.
  • For example, Wiz devices can be addressed in this way.
  • Below, we will show you how to send on/off commands to a smart home lamp using the T-WATCH.
  • The necessary UDP messages were found here:
https://seanmcnally.net/wiz-config.html
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.

  • For more information on smart home technology, see also:
12_Technikphilosophie/05_Fallstudien/01_Smart_Home
  • Bertko, C., Weber, T., Home Smart Home - Der praktische Einstieg in die Hausautomation, Hanser, München 2017.
  • Butz, A., Krüger, A., Mensch-Maschine-Interaktion, de Gruyter, Berlin 2017.
  • Sadek, I. et. al., Novel Unobtrusive Approach for Sleep Monitoring Using Fiber Optics in an Ambient Assisted Living Platform, S.48-60 in: Enhanced Quality of Life and Smart Living, Springer LNCS 10461, Cham 2017.
  • Seiderer, A., Dang, C.T., André, E., Exploring Opportunistic Ambient Notifications in the Smart Home to Enhance Quality of Live, S.151-160 in: Enhanced Quality of Life and Smart Living, Springer LNCS 10461, Cham 2017.
  • Treviranus, J., Teaching Our Machines to be Smart, Not Prejudiced, S.XIII in: Enhanced Quality of Life and Smart Living, Springer LNCS 10461, Cham 2017.

Preliminary test: Use of a Java/Processing sketch on a laptop/PC


Control the lamp from your PC.

Bild 0-1: Control the lamp from your PC.


https://youtu.be/Ht2dDGhvP4o -- Control the lamp from your PC, video.

  • Pressing the button alternately sends the switch-on and switch-off message to the lamp.
  • See in particular the callback method keyPressed()...
  • A hotspot was set up directly with the laptop.
  • The broadcast IP (here 10.42.0.255) must be determined from the respective hotspot network.
  • The port address is fixed and corresponds to the one accepted by the lamp, here 38899.
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

  • The hotspot hotspotK continued to be provided by the laptop.
  • Alternatively, a smartphone could be used to create the hotspot.
  • The name of the hotspot and the WPA2 password must be adjusted in the following source code.
  • If more than one lamp or socket is in use, the variable id in the sent message must be varied.
  • Once again, the TWATCH_PROC023 project serves as the basis and must be copied using "Save as".
  • Then only the main tab is changed.
  • Due to data type compatibility issues, all messages were provided twice: as const uint8_t to send them and as char to measure their length with strlen(...).

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.

  • At the touch of a button, the switch-on and switch-off messages are sent alternately via UDP.
  • If the WiFi connection is not yet established when the button is pressed, an attempt is made to renew it first.
  • The display shows whether the lamp is currently on or off.
Lamp off.

Bild 0-2: Lamp off.

Lamp on.

Bild 0-3: Lamp on.


https://youtu.be/KKv1UixNgjY -- Controlling a Wiz smart home lamp using a LilyGo T-WATCH V3, video.

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.