package com.yfyy.iotx;

import com.yfyy.iotx.rest.RestHandle;
import org.eclipse.jetty.server.Server;
import org.eclipse.paho.client.mqttv3.MqttException;

import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;

/**
 * 订阅云飞的数据
 */
public class MainApplication {

    private final static String deviceName2 = "867435059560631";
    private final static String deviceName3 = "867435059571406";
    private final static String deviceName4 = "867435059571364";
    private final static String deviceName5 = "867435059561571";
    private final static String deviceName6 = "867435059571489";
    private final static String deviceName7 = "866547055126570";

    private static final List<String> Device_Name_List = new ArrayList<>();

    static {
        Device_Name_List.add(deviceName2);
        Device_Name_List.add(deviceName3);
        Device_Name_List.add(deviceName4);
        Device_Name_List.add(deviceName5);
        Device_Name_List.add(deviceName6);
        Device_Name_List.add(deviceName7);
    }

    // 订阅云飞的数据
    public static void main(String[] args) throws MqttException {
        BridgeTsl bridgeTsl = new BridgeTsl();
        bridgeTsl.start();

        for (String deviceName : Device_Name_List) {
            // 新的，有重连
            String HOST = "tcp://8.136.98.49:61883";
            MqttClientThread mqttClientThread = new MqttClientThread(HOST,
                    "/yfkj/cbd/pub/" + deviceName,
                    "client" + deviceName,
                    deviceName);
            mqttClientThread.start();
        }

        try {
            InetSocketAddress inetSocketAddress = new InetSocketAddress("0.0.0.0", 9908);// 正式地址
            Server server = new Server(inetSocketAddress);
            server.setHandler(new RestHandle());
            server.start();
            server.join();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
