示例#1
0
def server():
    print "Server Started"

    # Read registers
    # Init Tags List
    Tags = []

    for x in range(0, 4000):
        Tags.append(SMonitor.Tag(0, x))

    while True:
        try:
            # SMonitor Set Values
            if ('smonitor' not in locals()):
                smonitor = SMonitor.SMServer(Tags, "c:\\S-Monitor\\test.prt")
            smonitor.Push()

            smonitor.Pull()

            Tags[2].value = Tags[0].value * Tags[1].value

            # Go to bed for 100 miliseconds
            time.sleep(0.1)

        except Exception, e:
            print('Something went terrible wrong: ' + str(e))
示例#2
0
def smonitor_to_json():
    try:
        Tags = []
        smonitor = SMonitor.SMClient(Tags, "C:\\S-Monitor\\S-Monitor.prt")
        enviar = "["
        smonitor.Pull()
        valores_nao_nulos = 0
        for tag in smonitor.Tags:
            if tag.name != "-----------------FREE-----------------":
                valores_nao_nulos += 1
        contador = 1
        for tag in smonitor.Tags:
            if tag.name != "-----------------FREE-----------------":
                enviar = enviar + "{" + "\"nome\"" + ":" "\"" + tag.name + "\"" + ","
                enviar = enviar + "\"valor\"" + ":" "\"" + str(
                    tag.value) + "\"" + ","
                enviar = enviar + "\"indice\"" + ":" "\"" + str(
                    tag.index) + "\"" + "}"
                if contador != valores_nao_nulos:
                    enviar = enviar + ","
                else:
                    enviar = enviar + "]"
                contador += 1
        return enviar
    except Exception, e:
        return str(e)
示例#3
0
def smonitor_to_sjon():
    try:
        Tags = []
        smonitor = SMonitor.SMClient(Tags, "C:\\S-Monitor\\S-Monitor.prt")
        enviar = "["
        smonitor.Pull()
        valores_nao_nulos = 0
        for tag in smonitor.Tags:
            if tag.name != "-----------------FREE-----------------":
                valores_nao_nulos += 1
        contador = 1
        for tag in smonitor.Tags:
            if tag.name != "-----------------FREE-----------------":
                enviar = enviar + "{" + "\"nome\"" + ":" "\"" + tag.name + "\"" + ","
                enviar = enviar + "\"valor\"" + ":" "\"" + str(
                    tag.value) + "\"" + ","
                enviar = enviar + "\"indice\"" + ":" "\"" + str(
                    tag.index) + "\"" + "}"
                if contador != valores_nao_nulos:
                    enviar = enviar + ","
                else:
                    enviar = enviar + "," + "{" + "\"dataHora\"" + ":" "\"" + time.strftime(
                        "%d-%m-%Y at %H:%M:%S") + "\"" + "}"
                    enviar = enviar + "]"
                contador += 1
        print enviar
        return enviar
    except Exception, e:
        print str(e)
示例#4
0
def client():
    print "Client Started"

    # Init Tags List
    Tags = []

    # Open PRT
    smonitor = SMonitor.SMClient(Tags, "c:\\S-Monitor\\S-Monitor.prt")
    while True:
        try:
            time.sleep(3)
            smonitor.Pull()
            #print str(Tags[0].name) + " => " + str(Tags[0].value) + " => " + str(Tags[0].index)
            Tags[1].value = Tags[1].value + 1
            if smonitor.Push():
                print "correu ppush"
            else:
                print "fudeu push"

            # tag in smonitor.Tags:
            #	print tag.name + " => " + str(tag.value) + " => " + str(tag.index)
        except Exception, e:
            print('Something went terrible wrong: ' + str(e))
示例#5
0
import sys
import os
from SMonitor import *

max_length = 3
monitor = SMonitor(max_length)
p = SMonitor(max_length)

while True:
    distance = monitor.get_avg()
    print(distance)

    pressure = p.psr_avg()
    print(pressure)
    time.sleep(0.1)
示例#6
0
    except Exception, e:
        print str(e)
        return False


class smonitor_thread(Thread):
    def __init__(self):
        Thread.__init__(self)

    def run(self):
        global string_to_send
        self.data = ""
        self.timestamp = ""
        while True:
            string_to_send = smonitor_to_json(self, self.data, self.timestamp)
            time.sleep(2)


if __name__ == '__main__':
    Tags = []
    smonitor = SMonitor.SMClient(
        Tags, r"C:\Users\Micael\Desktop\SMonitor Server\server.prt")
    processo = smonitor_thread()
    processo.start()
    time.sleep(2)
    webserver.run(debug=debug_on,
                  host='0.0.0.0',
                  port=80,
                  threaded=True,
                  use_reloader=False)
示例#7
0
import os
import sys
from PI_XBEE import *
from SMonitor import *

xb_comm = PI_XBEE('/dev/ttyAMA0')
monitor = SMonitor(3)

while True:
    pass
示例#8
0
import os
import sys
from PI_XBEE import *
from SMonitor import *

xb_comm = PI_XBEE('/dev/ttyAMA0')
monitor = SMonitor(3)

while True:
    average = monitor.monitor_thread()
    if average <= 5:
        xb_comm.send_msg(average)
示例#9
0
import os
import sys
import time
from PI_XBEE import *
from SMonitor import *

xb_comm = PI_XBEE('/dev/ttyAMA0')
monitor = SMonitor(3)

while True:
    time.sleep(.2)
    average = monitor.get_avg()
    xb_comm.send_msg(average)