예제 #1
0
파일: DNN_to_BC.py 프로젝트: Owor/sfiot
def senddata200(port):
    n = 200
    str_arr = []

    test_string = "H-;2019-12-05,00:00:00;N;;GateWayID;END"  #split by ';'

    # create data m*n array
    for i in range(0, 200):  #here '200' need to find meter number file
        str_arr.append(test_string.replace("H-", "H-" + str(i + 1)))

    #print(str_arr)		#show the simulate data format.
    #-----------------------------------------------------------------
    t0 = time.time()  #calculate the time about tranmission all data

    #test_string = pickle.dumps(test_string)
    socket_connect_END(port, str_arr, 200)
    # SendDatatoBC(my_bytes,200)

    print(
        "total time : " +
        str(time.time() - t0))  #calculate the time about tranmission all data
예제 #2
0
def SendData_to_BC_DNN(flag):
    print("subthread : Iot to BC & DNN start! ...")
    row_data = []

    for row in range(0, num_rows):
        for col in range(0, num_cols):
            print(col)
            row_data.append(
                str(title[col]) + ";2019-12-05,00:00:" +
                str(int(timestep[row])) + ";N;" + str(read_data[row][col]) +
                ";GatewayID;END")
            print(row_data)

            #socket_connect_END(BC_data_port, row_data, 1)		#send data to BC
            socket_connect_END(DNN_data_port, row_data, 1)  #send data to DNN

            row_data.clear()  #clear buffer
            time.sleep(2)
        print("===========================================")

        if (row >= 40000):
            break
예제 #3
0
HOST_from_IoT = '127.0.0.1'  # LOCAL HOST
PORT_to_model = 60001  # The port IN LOCAL HOST
from socket_lib.socket_listen_for_inner import listen_inner_network_END
from socket_lib.client_for_inner import socket_connect_END
import time
import numpy as np

#receive data
#while(True):
#rec_data = []
#receive data from IoT_to_DNN.py
rec = listen_inner_network_END(PORT_from_IoT)
#for i in rec:
#把原本每筆資料尾巴的END去掉
#i = i.strip(';END')
#rec_data.append(i)

print(len(rec))

#for j in rec:
#	   print("receive data:",j)
#print(len(rec))

#傳資料給DNN model做 Anomaly detection
socket_connect_END(PORT_to_model, rec, len(rec))

#time.sleep(2)

#清空繼續接收 smart grid 資料
#rec_data = []
예제 #4
0
        if (row >= 40000):
            break


""" data format : H-XX;2019-12-05,00:00:00;N;XX.X;GatewayID;END """

#====================================================================================================
#====================================================================================================
if __name__ == "__main__":
    row_data = []
    for row in range(0, num_rows):
        #print(row)
        for col in range(0, num_cols):
            temp = str(title[col]) + ";2019-12-05,00:00:" + str(
                int(timestep[row])) + ";N;" + str(
                    read_data[row][col]) + ";GatewayID;END"
            row_data.append(temp)

    print("data prepare finished")
    socket_connect_END(DNN_data_port, row_data, 40000)  #send data to DNN
    #SendData_to_BC_DNN(1)
    """
	parser = argparse.ArgumentParser(description='Please enter port: ')
	parser.add_argument("-p", "--port", type=str, default="NULL", help='Enter port number')

	args = parser.parse_args()

	if args.port !="NULL":
		senddata200(int(args.port))
	"""