Post Commands causing Overlay Map to refresh and excessive use of API

Alcaldejau10 months ago

Dear friends.
I am currently using the custom map from google in the Openwather Perciptation on top.
Everything was working fine, maps updating properly, openweather have a very special touch to the viewer but problem arouse when I get to creat some post functions to add devices to traccar.

I am running a script outside traccar to regularly check an outside API and if result is TRUE run post function to create a new device in traccar with all proper information, from there locations are uploadred using port 5055, but then the API is running the openweather map flickers, flashes and cause an excessive use of API (678 em 1 minute).

When I turn the API off, map is steady, working like a cham.

I get no errors on the post functions, no erros um updating locations but the for what it seems the use of the POST is causing the MAP to refresh way to often when - all things considered - all needed refreshing would be the vehicles locations and not the map itself!

Any ideas on what might the causing this isseu?

Anton Tananaev10 months ago

There must be something with your code.

Alcaldejau10 months ago

Yes, thats what I think but have no clue where to start looking.
Since locations are coming from websocket there is a lot of info going to the same port but it should not cause it.
Any clues on where start looking?

Anton Tananaev10 months ago

Not really and normally I don't provide support on the forum for customizations. That's not a transferrable knowledge that someone else can use.

Alcaldejau10 months ago

Here is the code.
All positions are flowing from a websocket:

    async devicesPosition(data) {
        const valid = async (data) => {
            const response = await fetch(${process.env.HOST_TRACCAR}/api/devices?uniqueId=${data.UserID}, {
                headers: {
                    "Cookie": await this.token(),
                    'Content-Type': 'application/json',
                },
            });

            const devices = await response.json();
            return devices.length;
        }

        if (await valid(data) === 1) {
            const api_url = ${process.env.HOST_TRACCAR}/api/positions;

            const api_url_test = http://localhost:5055/?deviceid=${data.UserID}&lat=${data.Latitude}&lon=${data.Longitude}&timestamp=${this.converterData()}&cell=208,10,12345,67890,50&wifi=00:11:22:33:44:55,-70

            // Set the headers
            const headers = {
                "Content-Type": "application/x-www-form-urlencoded",
                "Accept": "application/json",
            };

            const setPosition = await fetch(api_url_test, {
                headers: headers,
            });

            if (setPosition.status === 200) {
                console.log("Position added successfully!");
            }
        }
    }