コード例 #1
0
ファイル: user_main.c プロジェクト: n0bel/ESPrinkler
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();

}
コード例 #2
0
ファイル: communication.c プロジェクト: DirtyHairy/pebby
static void inbox_received(DictionaryIterator *iterator, void *context) {
    uint8_t messageType = get_message_type(iterator);

    switch (messageType) {
        case MESSAGE_TYPE_RESET_REQUEST:
            start_reset();
            break;

        default:
            LOG(APP_LOG_LEVEL_ERROR, "invalid incoming message type %i", (int)messageType);
            break;
    }
}
コード例 #3
0
ファイル: cgiwifi.c プロジェクト: kalismeras61/ESPrinkler
//This routine is ran some time after a connection attempt to an access point. If
//the connect succeeds, this gets the module in STA-only mode.
static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) {
	int x=wifi_station_get_connect_status();
	if (x==STATION_GOT_IP) {
		//Go to STA mode. This needs a reset, so do that.
		os_printf("Got IP. Going into STA+AP mode..\n");
		wifi_set_opmode(3);
		start_reset(); //system_restart();
	} else {
		connTryStatus=CONNTRY_FAIL;
		os_printf("Connect fail. Not going into STA-only mode.\n");
		//Maybe also pass this through on the webpage?
	}
}
コード例 #4
0
ファイル: cgiwifi.c プロジェクト: kalismeras61/ESPrinkler
//This cgi uses the routines above to connect to a specific access point with the
//given ESSID using the given password.
int ICACHE_FLASH_ATTR cgiWiFiSetMode(HttpdConnData *connData) {
	int len;
	char buff[1024];
	
	if (connData->conn==NULL) {
		//Connection aborted. Clean up.
		return HTTPD_CGI_DONE;
	}

	len=httpdFindArg(connData->getArgs, "mode", buff, sizeof(buff));
	if (len!=0) {
		os_printf("cgiWifiSetMode: %s\n", buff);
#ifndef DEMO_MODE
		wifi_set_opmode(atoi(buff));
		start_reset(); //system_restart();
#endif
	}
	httpdRedirect(connData, "/wifi");
	return HTTPD_CGI_DONE;
}
コード例 #5
0
ファイル: user_main.c プロジェクト: n0bel/ESPrinkler
int ICACHE_FLASH_ATTR cgiConfig(HttpdConnData *connData) {
	//os_printf("post len=%d %s\n",connData->post->len, connData->post->buff);
	char data[100];

	if (connData->post->len > 4)
	{
		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, "reset") == 0) {
					start_reset();
					os_sprintf(data,"{ \"reset\":\"Device reset in 2 seconds\" }");
					httpdSend(connData, data, -1);
					return HTTPD_CGI_DONE;
				}
				if (jsonparse_strcmp_value(&j, "config") == 0) {
					jsonparse_next(&j);
					while ( (type = jsonparse_next(&j) ) != 0)
					{
						if (type == JSON_TYPE_PAIR_NAME) {
							if (jsonparse_strcmp_value(&j, "name") == 0) {
								jsonparse_next(&j);
								jsonparse_next(&j);
								jsonparse_copy_value(&j, config.myname, sizeof(config.myname));
							}
							if (jsonparse_strcmp_value(&j, "zoffset") == 0) {
								jsonparse_next(&j);
								jsonparse_next(&j);
								// the following doesn't work with negative numbers
								//config.zoffset = jsonparse_get_value_as_int(&j);
								// so we do it the hard way
								char data[20];
								jsonparse_copy_value(&j, data, sizeof(data));
								// ok so atoi() doesn't work either
								config.zoffset = atoi(data);
#if 0
								if (data[0] == '-')
								{
									config.zoffset = 0 - atoi(data+1);
								}
								else
								{
									config.zoffset = atoi(data);
								}
#endif
								os_printf("zofffset=%d %08x\n",config.zoffset,config.zoffset);
							}
						}
					}
				}
			}
		}
		save_config();
	}
	os_sprintf(data,"{ config: { \"name\": \"%s\", \"zoffset\":%d } }",config.myname,config.zoffset);
	httpdSend(connData, data, -1);
	return HTTPD_CGI_DONE;
}