Allows my home wiz lights to be timed on and off according to a schedule.

Dependents:   heating

web/web-wiz-ajax.c

Committer:
andrewboyson
Date:
2021-05-10
Revision:
0:9af80a39adcc
Child:
5:ec0498d7d2c1

File content as of revision 0:9af80a39adcc:

#include  <stdint.h>
#include   <stdio.h>
#include <time.h>

#include "http.h"
#include "wiz.h"
#include "wiz-sun.h"
#include "wiz-sched.h"
#include "wiz-list.h"
#include "clk.h"

void WebWizAjax()
{
    HttpOk("text/plain; charset=UTF-8", "no-cache", NULL, NULL);
    
    HttpAddNibbleAsHex(WizTrace);
    HttpAddChar('\n');
    HttpAddChar('\f');
    WizListHttp();
    HttpAddChar('\f');
    
    struct tm tmLocal;
    struct tm tmUtc;
    ClkNowTmLocal(&tmLocal);
    ClkNowTmUtc  (&tmUtc);
    
    int minutesTodayUtc   = tmUtc.tm_hour   * 60 + tmUtc.tm_min;
    int minutesTodayLocal = tmLocal.tm_hour * 60 + tmLocal.tm_min;
    
    HttpAddInt32AsHex(minutesTodayLocal);
    HttpAddChar('\n');
    HttpAddInt32AsHex(minutesTodayUtc);
    HttpAddChar('\n');
    HttpAddInt32AsHex(WizSunRiseMinutes() - minutesTodayUtc + minutesTodayLocal);
    HttpAddChar('\n');
    HttpAddInt32AsHex(WizSunSetMinutes() - minutesTodayUtc + minutesTodayLocal);
    HttpAddChar('\n');
    HttpAddChar('\f');
    
    WizSchedHttp();
}