Пример #1
0
 def __init__(self, receiveQueue, sendQueue, ip=None):
     self.daemon = True
     super().__init__()
     self.receiver = receiveQueue
     self.sender = sendQueue
     if ip:
         network.call(sys.argv[1], whenHearCall=self.receive)
     else:
         network.wait(whenHearCall=self.receive)
Пример #2
0
def test_controller():
    global result, reason

    # CONNECT to the t controller
    trace("connecting...")
    network.call(ADDRESS, whenHearCall=incoming, port=PORT)
    trace("connected!")

    try:
        run_control_test()
    finally:
        try:
            trace("deallocating...")
            send("tel %s dealloc" % NAME)
            time.sleep(2)
            trace("closing...")
            network.hangUp()
        except Exception as e:
            print("Failed to dealloc: %s" % e)
Пример #3
0
 def __init__(self, queue, dstIP):
     self.queue = queue
     self.dstIP = dstIP
     network.call(dstIP, whenHearCall=heard)
Пример #4
0
  print "heard:" + phrase

  for a in phrase:
    if a == "\r" or a == "\n":
      pass # skip it
    elif a == "0":
      GPIO.output(LED, False)
    else:
      GPIO.output(LED, True)
  gotResponse = True

while True:
  while True:
    try:
      print "connecting to switch server"
      network.call(SERVER_IP, whenHearCall=heard)
      break
    except:
      print "refused"
      time.sleep(1)

  print "connected"

  while network.isConnected():
    gotResponse = False
    print "polling"
    network.say("?")

    while network.isConnected() and not gotResponse:
      print "waiting"  
      time.sleep(1)
Пример #5
0
     $$    $$$7       $$$$   $$D        
         $$$$$$$7   $$$$$$$$            
    $   $$$$$$$$$   $$$$$$$$$  $$       
  $$$  7$$$$$$$$$   $$$$$$$$$$ 7$$      
  $$$N 7$$$$$$$$7   $$$$$$$$$7 $$$$     
 $$$$  $$$$$$$$$     7$$$$$$7  7$$$     
  $$$   8$$$$$$       D$$$$7    $$$     
  7$           7$$$$$$          $$      
     7$$      7$$$$$$$$     $$$$        
    $$$$$7   $$$$$$$$$$$  D7$$$$$       
    $$$$$$$  $$$$$$$$$$7 $$$$$$$$       
     $$$$$$$  $$$$$$$$$  $$$$$$7        
     8$$$$$$   7$$$$$7  7$$$$$$N        
       $$$$$             $$$$7          
               $$$$$$$8                 
             $$$$$$$$$$$                
               $$$$$$$           """


if (len(sys.argv) >= 2):
  network.call(sys.argv[1], whenHearCall=heard)
else:  
  network.wait(whenHearCall=heard)



while network.isConnected():
  phrase = raw_input()
  print "me:" + phrase
  network.say(phrase)
Пример #6
0
def start(inp):
    a = list(network.call(inp))
    q = a.index(max(a))
    return p[q]
Пример #7
0
#Github: raspberrypilearning/networking-lessons

import network
import sys


def heard(phrase):
    print('them:' + phrase)


if (len(sys.argv) >= 2):
    network.call(sys.argv[1], whenHearCall=heard)
else:
    network.wait(whenHearCall=heard)

while network.isConnected():
    phrase = input()
    print("me:" + phrase)
    network.say(phrase)
Пример #8
0
# client.py  (c) 2013 @whaleygeek
#
# A demo client that pokes "hello" at a server once per second

import network
import time

network.call("localhost")

while network.isConnected():
  print("sending")
  network.say("hello")
  time.sleep(1)
  
Пример #9
0
# net_led.py  (c) 2013 @whaleygeek
#
# A network LED client - showing a LED that reflects remote switch status
#
# Connects to, and polls, a switch server once per second,
# and updates the LED status to reflect that of the switch.

import RPi.GPIO as GPIO
import time
import sys
import network

SERVER_IP = sys.argv[1]
LED = 11
GPIO.setmode(GPIO.BCM)
GPIO.setup(LED, GPIO.OUT)


def heard(phrase):
    a = phrase[0]
    if a == "0":
        GPIO.output(LED, False)
    else:
        GPIO.output(LED, True)


network.call(SERVER_IP, whenHearCall=heard)
while network.isConnected():
    network.say("?")
    time.sleep(1)
Пример #10
0
from time import sleep
import network
import random

tree_ip = "1.1.1.1"
network.call(tree_ip)
message = "1,255,255,255"
off = "1,0,0,0"

while True:
    time = random.randint(1, 5)
    network.say(message)
    sleep(0.5)
    network.say(off)
    sleep(time)

    random_y = random.randint((-d.max_y_coord) + 60, d.max_y_coord)
    # Set position to be either the positive or negative x maximum depending on their side and a random y value
    # Declare variable to hold the x coordinate, either positive or negative 630.0 in this case
    max_x_coord_decision = 0
    # If the side is "right," then the position should be positive
    if placement == "right":
        d.my_turtle.setpos(d.max_x_coord, random_y)
        max_x_coord_decision = d.max_x_coord
    # If the side is "left," then the position should be negative
    else:
        d.my_turtle.setpos(-d.max_x_coord, random_y)
        max_x_coord_decision = -d.max_x_coord
    # ----------
    # Call the other ip when needed and start do_work
    # Start first thread with the target coordinates and color - sets connection
    network.call(ip_of_other_rpi, whenHearCall=do_work)
    # Assign the function and data arguments to the first thread (before it closes)
    first_thread = threading.Thread(target=do_first_thread, kwargs={"data": f"{max_x_coord_decision} {random_y} "
                                                                            f"{start_color[0]} {start_color[1]} "
                                                                            f"{start_color[2]}"})
    # Do all the Turtle calls BEFORE sending off the first thread because turtle only works in the main loop!
    first_thread.start()

else:
    # Do all the Turtle calls BEFORE sending off the thread because turtle only works in the main loop!
    # Hide turtle so that it doesn't just start in the center of the screen
    d.my_turtle.hideturtle()
    # Assign the function to the second thread (before it joins the main thread)
    second_thread = threading.Thread(target=do_second_thread)
    # Start second thread
    second_thread.start()
Пример #12
0
  pass # ignore header
  
def handleBody(data):
  print(data)
  
def heard(msg):  
  global state
  if (state == 0): # response
    handleResponse(msg)
    state = 1
  elif (state == 1): # headers
    if (len(msg.strip()) != 0): # not end of headers
      handleHeader(msg)
    else: # end of headers
      state = 2
  elif (state == 2): # body
    handleBody(msg)
  

# main program starts here

network.call("localhost", port=port, whenHearCall=heard)
network.say("GET " + url + " " + proto_ver)
network.say("")
network.say("")

while network.isConnected():
  time.sleep(1)