- insert into sensor_values(sensor_id,parameter_id,timestamp,value)
- values(lSID,lSTPID,current_timestamp(),pValue);
+
+ if lSTPID>=0 then
+
+ if pTimestamp is null then
+ set lTime:=current_timestamp();
+ else
+ set lTime:=pTimestamp;
+ end if;
+
+ insert into sensor_values(sensor_id,parameter_id,timestamp,value)
+ values(lSID,lSTPID,lTime,pValue);
+
+ set lDay:=DATE(lTime);
+ select count(*) into lCnt from calendar where sensor=lSID and day=lDay;
+ if lCnt=0 then
+ insert into calendar(day,sensor) values(lDay,lSID);
+ end if;
+
+ select count(*) into lCnt from sensors_ranges where sensor=lSID and day=lDay and parameter=lSTPID;
+ if lCnt=0 then
+ insert into sensors_ranges(day,sensor,parameter,min,max) values (lDay,lSID,lSTPID,pValue,pValue);
+ else
+ update sensors_ranges
+ set
+ min=LEAST(min,pValue),
+ max=GREATEST(max,pValue)
+ where
+ day=lDay and sensor=lSID and parameter=lSTPID;
+ end if;
+ end if;
+ else
+ insert into error_log(timestamp,text)
+ values (current_timestamp(),CONCAT("Failed to submit ",pSType,",",pSID,",",pParam,",",pValue));