Exemple #1
0
def generate__two_traces(ConfigGile):
    with open(ConfigGile) as config_file:
        plotly_user_config = json.load(config_file)
    username = plotly_user_config['plotly_username']
    api_key = plotly_user_config['plotly_api_key']
    stream_tokenA = plotly_user_config['plotly_streaming_tokens'][0]
    stream_tokenB = plotly_user_config['plotly_streaming_tokens'][1]
    data = [{
        'x': [],
        'y': [],
        "name": "Ambient Temp",
        'type': 'scatter',
        'mode': 'lines+markers',
        'line': {
            'color': 'rgba(106, 45, 172, 1)'
        },
        'stream': {
            'token': stream_tokenA,
            'maxpoints': 60
        }
    }, {
        'x': [],
        'y': [],
        "name": "Water Temp",
        'type': 'scatter',
        'mode': 'lines+markers',
        'line': {
            'color': 'rgba(215, 40, 44, 1)'
        },
        'stream': {
            'token': stream_tokenB,
            'maxpoints': 60
        }
    }]
    p = plotly.plotly(username, api_key)
    p.plot(data,
           fileopt='overwrite',
           layout={
               'autosize': True,
               'showlegend': True,
               'yaxis': {
                   'range': [0, 40],
                   'title': 'Temp(C)'
               },
               'xaxis': {
                   'title': 'Time'
               }
           })
    s0 = plotly.stream(stream_tokenA)
    s1 = plotly.stream(stream_tokenB)
    return s0, s1
Exemple #2
0
def generate__two_traces(ConfigGile):
    with open(ConfigGile) as config_file:
        plotly_user_config = json.load(config_file)
    username = plotly_user_config['plotly_username']
    api_key = plotly_user_config['plotly_api_key']
    stream_tokenA = plotly_user_config['plotly_streaming_tokens'][0]
    stream_tokenB = plotly_user_config['plotly_streaming_tokens'][1]
    data = [{'x': [], 'y': [],"name":"Ambient Temp", 'type': 'scatter', 'mode': 'lines+markers', 'line': {'color': 'rgba(106, 45, 172, 1)'},
         'stream': {'token': stream_tokenA, 'maxpoints': 60}},
        {'x': [], 'y': [],"name":"Water Temp", 'type': 'scatter', 'mode': 'lines+markers', 'line': {'color':  'rgba(215, 40, 44, 1)'},
            'stream': {'token': stream_tokenB, 'maxpoints': 60}}]
    p = plotly.plotly(username, api_key)
    p.plot(data, fileopt='overwrite',layout = {'autosize': True, 'showlegend':True,'yaxis': {'range': [0,40],'title':'Temp(C)'},'xaxis': {'title':'Time'}})
    s0 = plotly.stream(stream_tokenA)
    s1 = plotly.stream(stream_tokenB)
    return s0,s1
Exemple #3
0
 def __init__(self, stream_tokens):
     """ Store the stream tokens in an object 
      so that the message handler can access them
     """
     self.streams = {}
     for token in stream_tokens:
         self.streams[token] = plotly.stream(token)
Exemple #4
0
def streamdata():

    s0 = plotly.stream(stream_tokens[0])
    s1 = plotly.stream(stream_tokens[1])
    s2 = plotly.stream(stream_tokens[2])

    while True:
        moment, vin, vstor, batok, lux = logfunc(
            os.path.join(logfolder, filename))
        s0.write({'x': moment, 'y': vin})
        s1.write({'x': moment, 'y': vstor})
        s2.write({'x': moment, 'y': lux})
        time.sleep(0.5)
    s0.close()
    s1.close()
    s2.close()
 def __init__(self, stream_tokens):
     ''' Store the stream tokens in an object
      so that the message handler can access them
     '''
     self.streams = {}
     self.data = {}
     self.last_write = {} 
     for token in stream_tokens:
         self.streams[token] = plotly.stream(token)
         self.data[token] = [] # {'avg': 0, 'max': 0, 'min': 0, 'n': 0}
         self.last_write[token] = datetime.datetime.now()
def creatStreamingGraph(fileName, ConfigGile,chanID):
    with open(ConfigGile) as config_file:
        plotly_user_config = json.load(config_file)
    username = plotly_user_config['plotly_username']
    api_key = plotly_user_config['plotly_api_key']
    stream_token = plotly_user_config['plotly_streaming_tokens'][chanID]
    stream_server = 'http://stream.plot.ly'

    p = plotly.plotly(username, api_key)
    layout = {'autosize': True, 'showlegend':True,'legend': {"x" : 1, "y" : 1},"xaxis": {"title":"Time"},"yaxis": {"title":"Temp (C)"}}
    p.plot([{'x': [],'y': [],"name":fileName,'type': 'scatter', 'mode': 'lines+markers','stream': {'token': stream_token,'maxpoints': 60}}],filename=fileName, fileopt='overwrite',layout = layout, world_readable=True)
    s = plotly.stream(stream_token)
    return s
def generateThreeTrace(ConfigGile):
    with open(ConfigGile) as config_file:
        plotly_user_config = json.load(config_file)
    username = plotly_user_config['plotly_username']
    api_key = plotly_user_config['plotly_api_key']
    stream_tokenA = plotly_user_config['plotly_streaming_tokens'][3]
    stream_tokenB = plotly_user_config['plotly_streaming_tokens'][4]
    stream_tokenC = plotly_user_config['plotly_streaming_tokens'][5]
    stream_server = 'http://stream.plot.ly'
    layout = {'autosize': True, 'showlegend':True,'legend': {"x" : 1, "y" : 1},"xaxis": {"title":"Time"},"yaxis": {"title":"Temp (C)"}}
    data = [
        {'x': [], 'y': [],"name":"DS18B20 1", 'type': 'scatter', 'mode': 'lines+markers', 'line': {'color': 'rgba(106, 45, 172, 1)'},
         'stream': {'token': stream_tokenA, 'maxpoints': 60}},
        {'x': [], 'y': [],"name":"DS18B20 2", 'type': 'scatter', 'mode': 'lines+markers', 'line': {'color':  'rgba(215, 40, 44, 1)'},
            'stream': {'token': stream_tokenB, 'maxpoints': 60}},
        {'x': [], 'y': [],"name":"MLX90614 1", 'type': 'scatter', 'mode': 'lines+markers', 'line': {'color': 'rgba(106, 240, 44, 1)'},
            'stream': {'token': stream_tokenC, 'maxpoints': 60}}]
    p = plotly.plotly(username, api_key)
    p.plot(data, fileopt='overwrite',layout = {'autosize': True, 'showlegend':True,'legend': {"x" : 1, "y" : 1}})
    s4 = plotly.stream(stream_tokenA)
    s5 = plotly.stream(stream_tokenB)
    s6 = plotly.stream(stream_tokenC)
    return s4, s5, s6
#!/usr/bin/python
import datetime
import serial
import RPi.GPIO as GPIO
import plotly

tokens = ['token1', 'token2']
username = '******'
api_key = 'plotly_api_key_here'

p = plotly.plotly(username, api_key)
streams = [plotly.stream(token) for token in tokens]

# Initialize plot with stream tokens
print p.plot([{
    'x': [],
    'y': [],
    'type': 'scatter',
    'stream': {
        'token': token,
        'maxpoints': 40
    }
} for token in tokens],
             filename='Atlas Streaming Multiplexer',
             fileopt='overwrite')

# Set multiplexer to read 00 by setting S0 and S1 to low
GPIO.cleanup()
GPIO.setmode(GPIO.BOARD)
S0_pin = 18
S1_pin = 22
#!/usr/bin/python 
import datetime
import serial
import RPi.GPIO as GPIO
import plotly
 
tokens = ['token1', 'token2']
username = '******'
api_key = 'plotly_api_key_here'
 
p = plotly.plotly(username, api_key)
streams = [plotly.stream(token) for token in tokens]
 
# Initialize plot with stream tokens
print p.plot([{
    'x': [],
    'y': [],
    'type': 'scatter',
    'stream': {
        'token': token,
        'maxpoints': 40
        }
    } for token in tokens],
    filename='Atlas Streaming Multiplexer',
    fileopt='overwrite')
 
# Set multiplexer to read 00 by setting S0 and S1 to low
GPIO.cleanup()
GPIO.setmode(GPIO.BOARD)
S0_pin = 18
S1_pin = 22
def read_temp(device_file_no):
    lines = read_temp_raw(device_file_no)
    while lines[0].strip()[-3:] != 'YES':
        time.sleep(0.2)
        lines = read_temp_raw(device_file_no)
    equals_pos = lines[1].find('t=')
    if equals_pos != -1:
        temp_string = lines[1][equals_pos+2:]
        temp_c = float(temp_string) / 1000.0
        temp_f = temp_c * 9.0 / 5.0 + 32.0
        return round(temp_f,0)

initPlotly()		

stream_1 = plotly.stream(stream_token[0])
stream_2 = plotly.stream(stream_token[1])
stream_3 = plotly.stream(stream_token[2])
stream_4 = plotly.stream(stream_token[3])

while True:
	timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

	pump_status=0
	drain_status=0
	
	with open(pump_file, "r") as fo:
				fo.seek(0, 0)
				pump_status = fo.read(1)
	fo.closed
	
Exemple #11
0
def handlePlotlyMessages(msg):
    print msg
    s = plotly.stream(stream_token)
    s.write(json.loads(msg))
import plotly
import time

while True:
    try:
        s = plotly.stream('ds5xbsv9il')
        while True:
            s.write({'x': time.time(), 'y': time.time()})
            time.sleep(1)
    except KeyboardInterrupt:
        break
    except:
        time.sleep(1)
        try:
            s.close()
        except:
            pass
def plotly1(msg):
    print msg
    s = plotly.stream(stream_token1)
    data = json.loads(msg)
    data['x'] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
    s.write(data) 
Exemple #14
0
    plotly_user_config = simplejson.load(config_file)

username = plotly_user_config['plotly_username']
api_key = plotly_user_config['plotly_api_key']
stream_token = plotly_user_config['plotly_streaming_tokens'][0]
p = plotly.plotly(username, api_key)
p.plot([{
    'x': [],
    'y': [],
    'type': 'scatter',
    'mode': 'lines',
    'stream': {
        'token': stream_token,
        'maxpoints': 500
    }
}],
       filename='Time-Series',
       fileopt='overwrite')
s = plotly.stream(stream_token)

while True:
    r = requests.get("https://api.spark.io/v1/devices/50ff70065067545638"
                     "200387/result?access_token="
                     "05970b102f05cd6f6cce1c5dcebccb096a222a63")
    x_data_point = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
    a = simplejson.loads(r.text)
    y_data_point = simplejson.loads(a['result'])['data1']
    print x_data_point, y_data_point
    s.write({'x': x_data_point, 'y': y_data_point})
    print "written", x_data_point
Exemple #15
0
# The `iplot` command will embed our plotly graph as an iframe in this notebook
# Each plotly graph has a unique url that you can share and anyone can view 
# your streaming graph in real-time
p.iplot([{'x': [], 'y': [], 'type': 'scatter', 'mode': 'lines',
            'stream': {'token': stream_token, 'maxpoints': 3600}
          }],
        filename='Is-Jimmies-Cold', fileopt='extend')


# Now stream! Write to a plotly stream object
# Our data will be in the the form:
# {'x': x_data, 'y':y_data}
# Each point that we yield will get shipped through plotly's servers
# to the graph your web-browser, updating it in real-time

s = plotly.stream(stream_token)
i=0

while True:
    i+=1

    (stdout, stderr) = Popen(["./get-temp.sh"], stdout=PIPE).communicate()
    # log current time and a random number
    x_data_point = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
    y_data_point = stdout
    print('Sending...', 'x',x_data_point,'y',y_data_point)
    s.write({'x': x_data_point, 'y': y_data_point})
    time.sleep(60)

s.close()
#!/usr/bin/python

import datetime
import plotly
import serial

token = 'stream_token'
username = '******'
api_key = 'plotly_api_key_here'

p = plotly.plotly(username, api_key)
stream = plotly.stream(token)

p.plot([{
    'x': [],
    'y': [],
    'type': 'scatter',
    'stream': {
        'token': token,
        'maxpoints': 100
    }
}],
       filename='Atlas Streaming dOxy',
       fileopt='overwrite')

# Serial code adapted from: https://www.atlas-scientific.com/_files/code/pi_sample_code.pdf
print "Atlas is now Streaming to Plotly!"
usbport = '/dev/ttyAMA0'
ser = serial.Serial(usbport, 38400)
# turn on the LEDs
ser.write("L1\r")