Exemplo n.º 1
0
void ICACHE_FLASH_ATTR onesec(void *arg)
{
	int i;
	struct time_entry *t;
	int recompute = 0;
	static int first_compute = 0;
	if (!first_compute)
	{
		if (time() > SANE_TIME)
		{
			first_compute = 1;
			compute_times();
		}
		os_printf("waiting for sane_time %d %d\n",sntp_get_current_timestamp(),time());
		return;
	}
	for (i = 1; i <=8; i++)
	{
		if (countdown[i-1])
		{
			countdown[i-1]--;
			if (countdown[i-1] == 0)
			{
				set_relay(i,0,0);
			}
		}
	}

	time_t now = time();
	for (i = time_count, t = times; i > 0; i--, t++)
	{
		//os_printf("zone=%d now=%d ontime=%d recompute=%d ctr=%d\n",t->zone,now, t->ontime, recompute, i);
		if (now >= t->ontime)
		{
			recompute++;

			if (t->zone == 100)
			{
				start_reset();
			}
			else if (t->zone == 101)
			{
				set_all_relays_off();
			}
			else
			{
				set_relay(t->zone,1,t->duration);
			}
		}
	}

	if (recompute) compute_times();

}
Exemplo n.º 2
0
	/* compute prayer times at given julian date */
	void compute_day_times(double times[])
	{
		double default_times[] = { 5, 6, 12, 13, 18, 18, 18 };		// default times
		for (int i = 0; i < TimesCount; ++i)
			times[i] = default_times[i];

		for (int i = 0; i < NUM_ITERATIONS; ++i)
			compute_times(times);

		adjust_times(times);
	}
Exemplo n.º 3
0
int ICACHE_FLASH_ATTR cgiSched(HttpdConnData *connData) {
	struct sched_entry *s = config.scheds;

	os_printf("post len=%d %s\n",connData->post->len, connData->post->buff);

	if (connData->post->len > 10)
	{

		set_all_relays_off();

		config.sched_count = 0;
		s = config.scheds;

		struct jsonparse_state j;
		jsonparse_setup(&j, connData->post->buff, connData->post->len);

		int type;
		while ( (type = jsonparse_next(&j) ) != 0)
		{
			if (type == JSON_TYPE_PAIR_NAME) {
				if (jsonparse_strcmp_value(&j, "schedules") == 0) {
					jsonparse_next(&j);
					while ( (type = jsonparse_next(&j) ) != 0)
					{
						if (type == JSON_TYPE_ARRAY || type == ',')
						{
							jsonparse_next(&j);
							while ( (type = jsonparse_next(&j) ) != 0)
							{
								if (type == '}')
								{
									s++;
									config.sched_count++;
									break;
								}
								if (type == JSON_TYPE_PAIR_NAME) {
									if (jsonparse_strcmp_value(&j, "zone") == 0) {
										jsonparse_next(&j);
										jsonparse_next(&j);
										s->zone = jsonparse_get_value_as_int(&j);
									}
									if (jsonparse_strcmp_value(&j, "start") == 0) {
										jsonparse_next(&j);
										jsonparse_next(&j);
										s->start = jsonparse_get_value_as_int(&j);
									}
									if (jsonparse_strcmp_value(&j, "end") == 0) {
										jsonparse_next(&j);
										jsonparse_next(&j);
										s->end = jsonparse_get_value_as_int(&j);
									}
									if (jsonparse_strcmp_value(&j, "time") == 0) {
										jsonparse_next(&j);
										jsonparse_next(&j);
										s->time = jsonparse_get_value_as_int(&j);
									}
									if (jsonparse_strcmp_value(&j, "duration") == 0) {
										jsonparse_next(&j);
										jsonparse_next(&j);
										s->duration = jsonparse_get_value_as_int(&j);
									}
									if (jsonparse_strcmp_value(&j, "repeat") == 0) {
										jsonparse_next(&j);
										jsonparse_next(&j);
										s->repeat = jsonparse_get_value_as_int(&j);
									}
									if (jsonparse_strcmp_value(&j, "dow") == 0) {
										jsonparse_next(&j);
										jsonparse_next(&j);
										s->dow = jsonparse_get_value_as_int(&j);
									}
								}
							}
						}
					}
				}
			}
		}
		save_config();
		compute_times();
	}

	char *data = (char *)alloca(100*config.sched_count);
	char *p = data;
	s = config.scheds;
	int i;
	os_sprintf(p,"{ \"name\": \"%s\", \"time\": %d, \"schedules\":[ ",config.myname,time());
	p += strlen(p);
	for (i = config.sched_count, s = config.scheds; i > 0; i--, s++)
	{
		os_sprintf(p,"{\"zone\":%d,\"start\":%d,\"end\":%d,\"time\":%d,\"duration\":%d,\"repeat\":%d,\"dow\":%d},",
				s->zone,s->start,s->end,s->time,s->duration,s->repeat,s->dow);
		p += strlen(p);
	}
	p--;
	*p++ = ']';
	*p++ = '}';
	*p++ = '\0';
	httpdSend(connData, data, -1);
	return HTTPD_CGI_DONE;
}