Exemplo n.º 1
0
void setup() {
#ifdef ARDUINO_ARCH_AVR
	sleep_setup();	// if you want to use sleep, or use the optiboot watchdog
#endif
	//wdt_disable();

	Serial.begin(115200);
#ifdef ARDUINO_ARCH_AVR
	printf_begin();
#endif
	printf_P(PSTR("HomeMesh 1.0\r\n"));
	printf_P(PSTR("(c) koverg70 %s %s\r\n"), __DATE__, __TIME__);

	/*
	pinMode(LED_PIN, OUTPUT);
	for (int i=1; i<3; ++i) {
		digitalWrite(LED_PIN, HIGH);
		delay(500);
		digitalWrite(LED_PIN, LOW);
		delay(500);
	}
	*/

	printf_P(PSTR("NodeID: %d, CE pin: %d, CS pin: %d\r\n"), NODE_ID, NRF24_CE_PIN, NRF24_CS_PIN);

  	// a very simple RF24 radio test
	delay(500);

	mesh.setNodeID(NODE_ID);
	printf_P(PSTR("NodeID: %d, CE pin: %d, CS pin: %d\r\n"), NODE_ID, NRF24_CE_PIN, NRF24_CS_PIN);
	mesh.begin();
	printf_P(PSTR("NodeID: %d, CE pin: %d, CS pin: %d\r\n"), NODE_ID, NRF24_CE_PIN, NRF24_CS_PIN);

	// --- now we initialize the tasks the are regularily called with new messages and to process information ----

	addTask(new TimeSync(60000, 0));		// sync frequency and target node to require time from
#if NODE_ID == 0
	Master *master = new Master();
	addTask(master);					// TODO: where to store received data
#ifdef ESP8266
	addTask(new ESP8266Ntp());
	addTask(new ESP8266Web(master->getSensors()));
#else
//	addTask(new Wifi(master->getSensors()));
	addTask(new Ethernet(master->getSensors()));
#endif
#else
	addTask(new Sensors(0));				// the target node to send sensor data to
#endif
#ifdef SCHEDULE_PIN
	addTask(new Schedule(SCHEDULE_PIN));	// sync frequency and target node to require time from
#endif

	// ------------------------------------------------------------------------------------------------------------

  	for (int i = 0; i < taskCount; ++i) {
  		tasks[i]->begin();
		printf_P(PSTR("Task started: %s\r\n"), tasks[i]->name());
  	}
}