forked from cemaden-educacao/WPD-MobileApp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
924 B
29 lines
924 B
import moment from "moment";
|
|
import { useState } from "react";
|
|
import dataClient from "../api/Websockets/dataClient";
|
|
|
|
function getPluviometerData(geoLocation, setPluviometerData) {
|
|
const initialDate = moment().format("YYYY-MM-DDTHH:mm:ss");
|
|
const finalDate = moment().subtract(5, "days").format("YYYY-MM-DDTHH:mm:ss");
|
|
const time = finalDate +"/"+initialDate;
|
|
const endpoint =
|
|
dataClient +
|
|
`type=PLUVIOMETER_FORM&time=${time}&lat=${geoLocation.latitude}&lon=${geoLocation.longitude}&buffer=1`;
|
|
const socketObject = new WebSocket(endpoint);
|
|
|
|
socketObject.onmessage = ({ data }) => {
|
|
if (data != undefined) {
|
|
const dataObject = JSON.parse(data);
|
|
// console.log(dataObject.responseData);
|
|
if (dataObject?.success) {
|
|
setPluviometerData(dataObject);
|
|
}
|
|
} else {
|
|
setPluviometerData(null);
|
|
}
|
|
|
|
socketObject.close();
|
|
};
|
|
}
|
|
|
|
export default getPluviometerData;
|