package com.example.MeteoStarSpring.dop;

import com.example.MeteoStarSpring.components.DateTime;
import com.example.MeteoStarSpring.models.Post;
import com.example.MeteoStarSpring.repo.PostRepository;
import org.springframework.beans.factory.annotation.Autowired;

public class SmartStatic implements Runnable {

    @Autowired
    private PostRepository postRepository;


    private int time;
    private String ip, token;

    public SmartStatic(int time, String ip, String token) {
        this.time = time;
        this.ip = ip;
        this.token = token;
    }

    @Override
    public void run() {
            sbor();
    }

    private void sbor() {
        for (;;) {
            DateTime dt = new DateTime();

            Esp32Client client = new Esp32Client();
            client.Esp32GetJson(ip, token);

            //Post post = new Post(Integer.parseInt(client.getSvet()), Double.parseDouble(client.getVlashnost()), Double.parseDouble(client.getTemp()), dt.dt());
            //postRepository.save(post);

            try {
                Thread.sleep(time * 1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

}
