Beispiel #1
0
class ServerGui(QWidget):
    def __init__(self, parent=None, **kwargs):
        QWidget.__init__(self, parent, **kwargs)

        self.setWindowTitle("Server")

        self._running = False
        self._server = HttpServer(self)

        l = QGridLayout(self)
        l.addWidget(
            QPushButton("Start", self, checkable=True, clicked=self.startStop),
            0, 0)

        sgb = QGroupBox("Settings", self)
        sl = QFormLayout(sgb)
        l.addWidget(sgb, 1, 0)

        self._host = QLineEdit('127.0.0.1', self)
        sl.addRow("Host:", self._host)

        self._port = QSpinBox(self, value=8080, minimum=1024, maximum=99999)
        sl.addRow("Port:", self._port)

        rdl = QHBoxLayout()
        rdl.setContentsMargins(0, 0, 0, 0)
        self._rootDir = QLineEdit(QDir('./www').absolutePath(), self)
        rdl.addWidget(self._rootDir)
        rdl.addWidget(QPushButton("Browse...", self, clicked=self.setRootDir))
        sl.addRow("Root Directory:", rdl)

    @pyqtSlot()
    def startStop(self):
        self._running = self.sender().isChecked()

        self.sender().setText('Stop' if self._running else 'Start')

        if self._running:
            self._server.start(self._host.text(), self._port.value(),
                               self._rootDir.text())
        else:
            self._server.stop()

    @pyqtSlot()
    def setRootDir(self):
        current = self._rootDir.text()
        root = QFileDialog.getExistingDirectory(self,
                                                'Select Root Directory...',
                                                current)

        if not root: return
        self._rootDir.setText(root)
Beispiel #2
0
class ServerGui(QWidget):
    def __init__(self, parent=None, **kwargs):
        QWidget.__init__(self, parent, **kwargs)

        self.setWindowTitle("Server")

        self._running=False
        self._server=HttpServer(self)

        l=QGridLayout(self)
        l.addWidget(QPushButton("Start", self, checkable=True, clicked=self.startStop), 0, 0)

        sgb=QGroupBox("Settings", self)
        sl=QFormLayout(sgb)
        l.addWidget(sgb, 1, 0)

        self._host=QLineEdit('127.0.0.1', self)
        sl.addRow("Host:", self._host)

        self._port=QSpinBox(self, value=8080, minimum=1024, maximum=99999)
        sl.addRow("Port:", self._port)

        rdl=QHBoxLayout()
        rdl.setContentsMargins(0,0,0,0)
        self._rootDir=QLineEdit(QDir('./www').absolutePath(), self)
        rdl.addWidget(self._rootDir)
        rdl.addWidget(QPushButton("Browse...", self, clicked=self.setRootDir))
        sl.addRow("Root Directory:", rdl)

    @pyqtSlot()
    def startStop(self):
        self._running=self.sender().isChecked()

        self.sender().setText('Stop' if self._running else 'Start')

        if self._running:
            self._server.start(
                self._host.text(),
                self._port.value(),
                self._rootDir.text()
            )
        else: self._server.stop()

    @pyqtSlot()
    def setRootDir(self):
        current=self._rootDir.text()
        root=QFileDialog.getExistingDirectory(self, 'Select Root Directory...', current)

        if not root: return
        self._rootDir.setText(root)
analyzer = PingsAnalyzer( failtime, len( failovers ) )

try:    
    httpserver = HttpServer( port, analyzer )
except socket.error, e:
    print >> sys.stderr, "Error while starting http server:", e
    exit( 1 )

print "Replica process started. ReplicaProcessId = %s, Port = %d" % ( failover_id, port )
logger.trace( "Replica process started. ReplicaProcessId = %s, Port = %d" % ( failover_id, port ) )

become_daemon()
write_pid( pidfile )

httpserver.start()    

lasttime = {}
info = {}

while True:
    for hostport in redises:
        r = redis.Redis( hostport[ 0 ], port = int( hostport[ 1 ] ), socket_timeout = check_delay / 2 )
        role, master_host, master_port, used_memory = "", "", "", ""
        try:
            redis_info = r.info()
            if redis_info[ "loading" ] == 0:
                role = redis_info[ "role" ]
                used_memory = redis_info[ "used_memory" ]
                master_host = unicode( redis_info[ "master_host" ] )
                master_port = redis_info[ "master_port" ]
Beispiel #4
0
# print current local date & time
logger.debug('Date: ' + rtc.get_localdate())
logger.debug('Time: ' + rtc.get_localtime())

# initialize the MQTT module
logger.debug('Initializing MQTT...')
mqtt = MQTT(settings)

# initialize the fermentation process
logger.debug('Initializing main process logic...')
main_process = Process(fermenter_temp_ctrl, process_tim, recovery, wifi, mqtt)

# Set up HTTP server
logger.debug('Initializing Web server...')
web = HttpServer(main_process, wifi, rtc, settings)
web.start()
utime.sleep(3)
if web.is_started():
    logger.debug('HTTP service has started.')
led.set_color('green')  # 初始化全部完成后设置为绿色,表示处于待机状态

# Set up DNS Server
logger.debug('Initializing DNS...')
if MicroDNSSrv.Create({'*': '192.168.4.1'}):
    logger.debug("DNS service has started.")
else:
    logger.debug("Failed to start DNS service...")

# Check if the crash recovery is needed
if recovery.is_needed():
    logger.debug('Recovering the fermentation process...')
Beispiel #5
0
# 	'reca': 5,
# 	'recb': 23,
# 	'ctrl': 27
# }
# led = Pin(2, Pin.OUT)

## Cheap ESP32 WROOM-32 board with no spi RAM
pinmap = {
    'lpwm': 13,
    'ldir': 12,
    'lslp': 14,
    'leca': 26,
    'lecb': 27,
    'rpwm': 25,
    'rdir': 33,
    'rslp': 32,
    'reca': 34,
    'recb': 35,
    'ctrl': 15
}
led = Pin(2, Pin.OUT)

romp = RomiPlatform(pinmap)

# A suitable index.html file should be put in /www on the ESP32 internal storage
hsrv = HttpServer()  # Create the HTTP server on port 80
wsrv = RomiServer(romp, 8080,
                  debug=False)  # Create the web socket server on port 8080
print("Point your browser at:", hsrv.start())  # Start the HTTP server
print("Web socket URL:", wsrv.start())  # Start the web socket server