SHT30 온습도 모니터링 시스템 전체 소스(서버 PHP, STM32 펌웨어, SQL, 테스트). 전체 코드리뷰에서 도출된 보안 하드닝 10건 반영: - 요청 서명 HMAC-SHA256 전환(펌웨어 sig.c/서버 config.php/호스트 패리티 동시) - 재전송 방어 + 기본 API_KEY fail-closed + 디바이스 문자열 정제(api/sensor_data.php) - 오프라인 SMS 중복 발송 경합 제거(cron_heartbeat.php, 원자적 선점) - CSV 수식 주입 방지(monthly_report.php), 감사로그 회전 락(retention_cleanup.php) - 브루트포스 카운터 원자화(login.php), 예시 TOTP 비밀키 무효화, 마이그레이션 멱등화 _backup/(하드코딩 실 비밀값 포함)·config.local.php·런타임 상태는 .gitignore 제외.
30 lines
999 B
C
30 lines
999 B
C
/* =============================================================================
|
|
* sht30_convert.c
|
|
* ===========================================================================*/
|
|
#include "sht30_convert.h"
|
|
|
|
uint8_t sht30_crc8(const uint8_t *data, size_t len)
|
|
{
|
|
uint8_t crc = 0xFF;
|
|
for (size_t i = 0; i < len; i++) {
|
|
crc ^= data[i];
|
|
for (int b = 0; b < 8; b++) {
|
|
if (crc & 0x80) crc = (uint8_t)((crc << 1) ^ 0x31);
|
|
else crc = (uint8_t)(crc << 1);
|
|
}
|
|
}
|
|
return crc;
|
|
}
|
|
|
|
int sht30_parse(const uint8_t frame[6], double *temp_c, double *rh)
|
|
{
|
|
if (sht30_crc8(&frame[0], 2) != frame[2]) return -1;
|
|
if (sht30_crc8(&frame[3], 2) != frame[5]) return -2;
|
|
|
|
uint16_t raw_t = (uint16_t)((frame[0] << 8) | frame[1]);
|
|
uint16_t raw_rh = (uint16_t)((frame[3] << 8) | frame[4]);
|
|
|
|
if (temp_c) *temp_c = -45.0 + 175.0 * ((double)raw_t / 65535.0);
|
|
if (rh) *rh = 100.0 * ((double)raw_rh / 65535.0);
|
|
return 0;
|
|
}
|