forked from tidalvirus/alphaess-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
35 lines (25 loc) · 961 Bytes
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python3
#Server to fake www.alphaess.com port 7777 that batteries sync data to
import binascii
import socket
import struct
import sys
import re
import json
from crccheck.crc import Crc16Modbus
from datetime import datetime
from influxdb_client import InfluxDBClient, Point, WritePrecision
from influxdb_client.client.write_api import SYNCHRONOUS
HOST, PORT = "localhost", 7778
def server_program():
server_socket = socket.socket() # get instance
# look closely. The bind() function takes tuple as argument
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_socket.bind((HOST, PORT)) # bind host address and port together
# configure how many client the server can listen simultaneously
server_socket.listen(1)
conn, address = server_socket.accept() # accept new connection
print("Connection from: " + str(address))
while True:
if __name__ == '__main__':
server_program()