void C1Wire::ReportIlluminance(const std::string& deviceId, const float illuminescence) { if (illuminescence == -1000.0) return; unsigned char deviceIdByteArray[DEVICE_ID_SIZE] = { 0 }; DeviceIdToByteArray(deviceId, deviceIdByteArray); uint8_t NodeID = deviceIdByteArray[0] ^ deviceIdByteArray[1]; SendSolarRadiationSensor(NodeID, 255, illuminescence, "Solar Radiation"); }
void Meteostick::ParseLine() { if (m_bufferpos < 1) return; std::string sLine((char*)&m_buffer); std::vector<std::string> results; StringSplit(sLine, " ", results); if (results.size() < 1) return; //invalid data switch (m_state) { case MSTATE_INIT: if (sLine.find("# MeteoStick Version") == 0) { _log.Log(LOG_STATUS, sLine.c_str()); return; } if (results[0] == "?") { //Turn off filters write("f0\n"); m_state = MSTATE_FILTERS; } return; case MSTATE_FILTERS: //Set output to 'computer values' write("o1\n"); m_state = MSTATE_VALUES; return; case MSTATE_VALUES: #ifdef USE_868_Mhz //Set listen frequency to 868Mhz write("m1\n"); #else //Set listen frequency to 915Mhz write("m0\n"); #endif m_state = MSTATE_DATA; return; } if (m_state != MSTATE_DATA) return; if (results.size() < 3) return; unsigned char rCode = results[0][0]; if (rCode == '#') return; //#ifdef _DEBUG _log.Log(LOG_NORM, sLine.c_str()); //#endif switch (rCode) { case 'B': //temperature in Celsius, pressure in hPa if (results.size() >= 3) { float temp = static_cast<float>(atof(results[1].c_str())); float baro = static_cast<float>(atof(results[2].c_str())); SendTempBaroSensor(0, temp, baro, "Meteostick Temp+Baro"); } break; case 'W': //current wind speed in m / s, wind direction in degrees if (results.size() >= 5) { unsigned char ID = (unsigned char)atoi(results[1].c_str()); if (m_LastOutsideTemp[ID%MAX_IDS] != 12345) { float speed = static_cast<float>(atof(results[2].c_str())); int direction = static_cast<int>(atoi(results[3].c_str())); SendWindSensor(ID, m_LastOutsideTemp[ID%MAX_IDS], speed, direction, "Wind"); } } break; case 'T': //temperature in degree Celsius, humidity in percent if (results.size() >= 5) { unsigned char ID = (unsigned char)atoi(results[1].c_str()); float temp = static_cast<float>(atof(results[2].c_str())); int hum = static_cast<int>(atoi(results[3].c_str())); SendTempHumSensor(ID, temp, hum, "Outside Temp+Hum"); m_LastOutsideTemp[ID%MAX_IDS] = temp; m_LastOutsideHum[ID%MAX_IDS] = hum; } break; case 'R': //Rain //counter value (value 0 - 255), ticks, 1 tick = 0.2mm or 0.01in //it only has a small counter, so we should make the total counter ourselfses if (results.size() >= 4) { unsigned char ID = (unsigned char)atoi(results[1].c_str()); int raincntr = atoi(results[2].c_str()); float Rainmm = 0; if (m_LastRainValue[ID%MAX_IDS] != -1) { int cntr_diff = (raincntr - m_LastRainValue[ID%MAX_IDS])&255; Rainmm = float(cntr_diff); #ifdef RAIN_IN_MM //one tick is one mm Rainmm*=0.2f; //convert to mm; #else //one tick is 0.01 inch, we need to convert this also to mm //Rainmm *= 0.01f; //convert to inch //Rainmm *= 25.4f; //convert to mm //or directly Rainmm *= 0.254; #endif } m_LastRainValue[ID%MAX_IDS] = raincntr; if (m_ActRainCounter[ID%MAX_IDS] == -1) { //Get Last stored Rain counter float rcounter=GetRainSensorCounter(ID); m_ActRainCounter[ID%MAX_IDS] = rcounter; } m_ActRainCounter[ID%MAX_IDS] += Rainmm; SendRainSensor(ID, m_ActRainCounter[ID%MAX_IDS], "Rain"); } break; case 'S': //solar radiation, solar radiation in W / qm if (results.size() >= 4) { unsigned char ID = (unsigned char)atoi(results[1].c_str()); float Radiation = static_cast<float>(atof(results[2].c_str())); SendSolarRadiationSensor(ID, Radiation, "Solar Radiation"); } break; case 'U': //UV index if (results.size() >= 4) { unsigned char ID = (unsigned char)atoi(results[1].c_str()); float UV = static_cast<float>(atof(results[2].c_str())); SendUVSensor(ID, UV, "UV"); } break; case 'L': //wetness data of a leaf station //channel number (1 - 4), leaf wetness (0-15) if (results.size() >= 5) { unsigned char ID = (unsigned char)atoi(results[1].c_str()); unsigned char Channel = (unsigned char)atoi(results[2].c_str()); unsigned char Wetness = (unsigned char)atoi(results[3].c_str()); SendLeafWetnessRainSensor(ID, Channel, Wetness, "Leaf Wetness"); } break; case 'M': //soil moisture of a soil station //channel number (1 - 4), Soil moisture in cbar(0 - 200) if (results.size() >= 5) { unsigned char ID = (unsigned char)atoi(results[1].c_str()); unsigned char Channel = (unsigned char)atoi(results[2].c_str()); unsigned char Moisture = (unsigned char)atoi(results[3].c_str()); SendSoilMoistureSensor(ID, Channel, Moisture, "Soil Moisture"); } break; case 'O': //soil / leaf temperature of a soil / leaf station //channel number (1 - 4), soil / leaf temperature in degrees Celsius if (results.size() >= 5) { unsigned char ID = (unsigned char)atoi(results[1].c_str()); unsigned char Channel = (unsigned char)atoi(results[2].c_str()); float temp = static_cast<float>(atof(results[3].c_str())); unsigned char finalID = (ID * 10) + Channel; SendTempSensor(finalID, temp, "Soil/Leaf Temp"); } break; case 'P': //solar panel power in(0 - 100) if (results.size() >= 4) { unsigned char ID = (unsigned char)atoi(results[1].c_str()); float Percentage = static_cast<float>(atof(results[2].c_str())); SendPercentage(ID, Percentage, "power of solar panel"); } break; default: _log.Log(LOG_STATUS, "Unknown Type: %c", rCode); break; } }