Ejemplo n.º 1
0
void MySensor::begin(void (*_msgCallback)(const MyMessage &), uint8_t _nodeId, boolean _repeaterMode, uint8_t _parentNodeId, rf24_pa_dbm_e paLevel, uint8_t channel, rf24_datarate_e dataRate) {
	Serial.begin(BAUD_RATE);
	isGateway = false;
	repeaterMode = _repeaterMode;
	msgCallback = _msgCallback;

	if (repeaterMode) {
		setupRepeaterMode();
	}
	setupRadio(paLevel, channel, dataRate);

	// Read settings from EEPROM
	eeprom_read_block((void*)&nc, (void*)EEPROM_NODE_ID_ADDRESS, sizeof(NodeConfig));
	// Read latest received controller configuration from EEPROM
	eeprom_read_block((void*)&cc, (void*)EEPROM_LOCAL_CONFIG_ADDRESS, sizeof(ControllerConfig));
	if (cc.isMetric == 0xff) {
		// Eeprom empty, set default to metric
		cc.isMetric = 0x01;
	}

	if (_parentNodeId != AUTO) {
		nc.parentNodeId = _parentNodeId;
		autoFindParent = false;
	} else {
		autoFindParent = true;
	}

	if (_nodeId != AUTO) {
		// Set static id
		nc.nodeId = _nodeId;
	}

	// If no parent was found in eeprom. Try to find one.
	if (autoFindParent && nc.parentNodeId == 0xff) {
		findParentNode();
	}

	// Try to fetch node-id from gateway
	if (nc.nodeId == AUTO) {
		requestNodeId();
	}

	debug(PSTR("%s started, id %d\n"), repeaterMode?"repeater":"sensor", nc.nodeId);

	// Open reading pipe for messages directed to this node (set write pipe to same)
	RF24::openReadingPipe(WRITE_PIPE, TO_ADDR(nc.nodeId));
	RF24::openReadingPipe(CURRENT_NODE_PIPE, TO_ADDR(nc.nodeId));

	// Send presentation for this radio node (attach
	present(NODE_SENSOR_ID, repeaterMode? S_ARDUINO_REPEATER_NODE : S_ARDUINO_NODE);

	// Send a configuration exchange request to controller
	// Node sends parent node. Controller answers with latest node configuration
	// which is picked up in process()
	sendRoute(build(msg, nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_CONFIG, false).set(nc.parentNodeId));

	// Wait configuration reply.
	waitForReply();
}
Ejemplo n.º 2
0
void MyGateway::begin(rf24_pa_dbm_e paLevel, uint8_t channel, rf24_datarate_e dataRate, void (*inDataCallback)(char *)) {
	Serial.begin(BAUD_RATE);
	repeaterMode = true;
	isGateway = true;
	setupRepeaterMode();

	if (inDataCallback != NULL) {
		useWriteCallback = true;
		dataCallback = inDataCallback;
	} else {
		useWriteCallback = false;
	}

	nc.nodeId = 0;
	nc.distance = 0;
	inclusionMode = 0;
	buttonTriggeredInclusion = false;
	countRx = 0;
	countTx = 0;
	countErr = 0;

	// Setup led pins
	pinMode(pinRx, OUTPUT);
	pinMode(pinTx, OUTPUT);
	pinMode(pinEr, OUTPUT);
	digitalWrite(pinRx, LOW);
	digitalWrite(pinTx, LOW);
	digitalWrite(pinEr, LOW);

	// Setup digital in that triggers inclusion mode
	pinMode(pinInclusion, INPUT);
	digitalWrite(pinInclusion, HIGH);

	// Set initial state of leds
	digitalWrite(pinRx, HIGH);
	digitalWrite(pinTx, HIGH);
	digitalWrite(pinEr, HIGH);


	// Start up the radio library
	setupRadio(paLevel, channel, dataRate);
	RF24::openReadingPipe(WRITE_PIPE, BASE_RADIO_ID);
	RF24::openReadingPipe(CURRENT_NODE_PIPE, BASE_RADIO_ID);
	RF24::startListening();

	// Add led timer interrupt
    MsTimer2::set(300, ledTimersInterrupt);
    MsTimer2::start();

	// Add interrupt for inclusion button to pin
	PCintPort::attachInterrupt(pinInclusion, startInclusionInterrupt, RISING);

	// Send startup log message on serial
	serial(PSTR("0;0;%d;0;%d;Gateway startup complete.\n"),  C_INTERNAL, I_GATEWAY_READY);
}
Ejemplo n.º 3
0
void setup()
{
  Serial.begin(SERIAL_BAUD);

  // initialize the H/W
  setupRadio();
  setupLuminositySensor();
  setupTempHumiditySensor();

  // initialize LED digital pin as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}
Ejemplo n.º 4
0
void Smarty::setupSmarty() {
	Serial.begin(115200);
	if (!setupRadio())
		Serial.println("Error initializing nrf24l01");
	else
		sendDebug("Success initializing nrf24l01");
	sendDebug("I am smarty # %d", m_config.m_smartyID);

	m_radio.openWritingPipe(m_destAddress);     // address of combrick

	m_radio.openReadingPipe(SMARTY_RX_PIPE, m_localAddress);    // smarty address
	//m_radio.openReadingPipe(BROADCAST_RX_PIPE, m_broadcastAddress); // broadcast address

	m_radio.startListening();
}
Ejemplo n.º 5
0
void DTCGateway::begin(uint8_t channel, void(*inDataCallback)(char*))
{
    Serial.begin(BAUD_RATE);
    //while (!Serial){};
    delay(1000);

    isGateway = true;

    dataCallback = inDataCallback;

    nc.nodeId = GATEWAY_ADDRESS;

    countRx = 0;
    countTx = 0;
    countErr = 0;

    // Setup led pins
    pinMode(pinRx, OUTPUT);
    pinMode(pinTx, OUTPUT);
    pinMode(pinEr, OUTPUT);

    digitalWrite(pinRx, LOW);
    digitalWrite(pinTx, LOW);
    digitalWrite(pinEr, LOW);
    delay(500);
    digitalWrite(pinRx, HIGH);
    digitalWrite(pinTx, HIGH);
    digitalWrite(pinEr, HIGH);


    // Start up the radio library
    setupRadio(channel);
    //RF24::openReadingPipe(WRITE_PIPE, BASE_RADIO_ID);
    //RF24::openReadingPipe(CURRENT_NODE_PIPE, BASE_RADIO_ID);
    //RF24::startListening();

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

    //Serial.println(getVersion().c_str());
    //if (!setOprToStation())
    //	Serial.println("Failed to set Station");
    //Serial.println(getWifiModeList().c_str());

    //nc.gwMac = getMacAddress






    // Add led timer interrupt
    MsTimer2::set(300, ledTimersInterrupt);
    MsTimer2::start();

    // Send startup log message on serial
    serial(PSTR("0;0;%d;%d;Gateway started.\n"), C_INTERNAL, I_GATEWAY_READY);
}