コード例 #1
0
void VehicleTrafficLight::goSequenceAnimationStep(Sequencer & sequencer, uint8_t step) {
    switch (step) {
        case 1:
            setYellow();
            sequencer.nextWithDelay(VECHILE_GO_YELLOW_ms);
            break;
        case 2:
            setGreen();
            break;
    }
}
コード例 #2
0
void VehicleTrafficLight::stopSequenceAnimationStep(Sequencer & sequencer, uint8_t step) {
    switch (step) {
        case 1:
            setGreenPulsing();
            sequencer.nextWithDelay(VECHILE_STOP_GREEN_BLINK_ms);
            break;
        case 2:
            setYellow();
            sequencer.nextWithDelay(VECHILE_STOP_YELLOW_ms);
            break;
        case 3:
            setRed();
            break;
    }
}
コード例 #3
0
void save_value(String sensorId, String value) {
	printCurTime();
	value.replace(" ", "");
	//Build a HTTP GET string to store the update
//	String URI_STRING = "GET /ping/";
	String URI_STRING = "GET /u/";
	URI_STRING += wifi.getApMac();
	URI_STRING += "/";
	URI_STRING += sensorId;
	URI_STRING += "?rv=";
	URI_STRING += value;
	URI_STRING += " HTTP/1.0\r\n\r\n";
//	String URI_STRING = "GET /api/postvalue/?token=";
//	URI_STRING+=API_KEY;
//	URI_STRING += "&variable=";
//	URI_STRING += sensorId;
//	URI_STRING += "&value=";
//	URI_STRING += value;
//	URI_STRING += "\r\n\r\n";
	debugSerial2.print(F("URI_STRING.length(): "));
	debugSerial2.println(URI_STRING.length());
	debugSerial2.print(F("URI_STRING: "));
	debugSerial2.println(URI_STRING);
	char uriCharBuffer[URI_STRING_BUFFER_LENGTH];
	memset(uriCharBuffer, 0, URI_STRING_BUFFER_LENGTH);
	URI_STRING.toCharArray(uriCharBuffer, URI_STRING_BUFFER_LENGTH);

//	uint8_t responseBuffer[256] = { 0 };
	for (int i = 0; i < HTTP_RETRIES; i++) {
		debugSerial2.print(F("HTTP_RETRIES: "));
		debugSerial2.print(i);
		printCurTime();
		bool tcpEstablished = false;
		if (wifi.createTCP(HOST_NAME, HOST_PORT)) {
			tcpEstablished = true;
			debugSerial2.print(F("create tcp ok"));
			printCurTime();
		} else {
			debugSerial2.print(F("create tcp err"));
			printCurTime();
			setYellow();
			if (i + 1 == HTTP_RETRIES) {
				wifiConnected = false;
				setRed();
			}
		}
		if (wifiConnected && tcpEstablished) {
			bool httpGetOk = false;
			if (!httpGetOk) {
				wifi.send((const uint8_t*) uriCharBuffer,
						strlen(uriCharBuffer));

				//		uint32_t len = wifi.recv(responseBuffer, sizeof(responseBuffer), 10000);

				httpGetOk = wifi.recvHTTP( HTTP_REQ_TIMEOUT);
			}

			debugSerial2.print(F("httpGetOk: "));
			debugSerial2.print(httpGetOk);
			printCurTime();
//		if (len > 0) {
//			debugSerial2.print(F("Received:["));
//			for (uint32_t i = 0; i < len; i++) {
//				debugSerial2.print((char) responseBuffer[i]);
//			}
//			debugSerial2.print(F("]\r\n"));
//		} else {
//			wifiConnected = false;
//		}

			if (httpGetOk) {
				setGreen();
				checkAndReleaseConnection();
				break;
			} else {
				setYellow();
				checkAndReleaseConnection();
			}

			calcAndDoDelay(i);
		} else {
			debugSerial2.print(F("Failed TCP connection test"));
			checkAndReleaseConnection();
			printCurTime();
			setYellow();
			calcAndDoDelay(i);
		}
	}

}