Ejemplo n.º 1
0
def send(serialid, filepath, device):
    global ini, public_serialid
    try:
        slider.msg_log("start sending...")
        if ini.get("monitor", "mode") == "public":
            # public mode, so use public_serialid
            serialid = public_serialid
        now = datetime.datetime.now()  # 時刻の取得
        now_string = now.strftime("%Y/%m/%d %H:%M:%S")
        files = {'upfile': open(filepath, 'rb')}
        payload = {
            'serial_id': serialid,
            'device': device,
            'datetime': now_string
        }
        send_data(payload, files)
        #    comand_str = 'curl --insecure -k -F "upfile=@' + filepath + '" -F "serial_id='+serialid+ '" -F "device='+device+'" '+requests.post(ini.get("server", "url_base")) + 'postpic.php'+ '--retry 30'
        #    print command_str
        #    p = subprocess.check_call(command_str, shell=True)
        slider.msg_log("end sending...")
        slider.network_ok_report()
    except IOError:
        #    slider.io_error_report()
        slider.network_io_error_report()
    except:
        slider.unknown_error_report()
Ejemplo n.º 2
0
def send_data(payload, files):
    global ini
    if ini.get("send", "protocol") == "http":
#        r = requests.post(ini.get("server", "url_base") + 'postpic.php', data=payload, files=files, timeout=10, verify=False)
        r = requests.post(ini.get("server", "url_base") + 'postpic.php', data=payload, files=files, timeout=10, cert=os.path.dirname(os.path.abspath(__file__))+'/slider.pem', verify=False)
        slider.msg_log("by http.")
    elif ini.get("send", "protocol") == "mqtt":
        mqttclient.publish(ini.get("mqtt", "topic"), json.JSONEncoder().encode(payload))
        slider.msg_log("by mqtt.")
Ejemplo n.º 3
0
def send_data(payload):
    global ini
    if ini.get("send", "protocol") == "http":
        #        r = requests.post(ini.get("server", "url_base") + 'postdata.php', data=payload, timeout=10, verify=False)
        r = requests.post(ini.get("server", "url_base") + 'postdata.php',
                          data=payload,
                          timeout=10,
                          cert=os.path.dirname(os.path.abspath(__file__)) +
                          '/slider.pem',
                          verify=False)
        slider.msg_log("by http.")
    elif ini.get("send", "protocol") == "mqtt":
        mqttclient.publish(ini.get("mqtt", "topic"),
                           json.JSONEncoder().encode(payload))
        slider.msg_log("by mqtt.")
Ejemplo n.º 4
0
def send(serialid, name, value):
  global ini, public_serialid
  try:
    slider.msg_log ("start sending...")
    if ini.get("monitor", "mode") == "public":
      # public mode, so use public_serialid
      serialid = public_serialid
    now = datetime.datetime.now() # 時刻の取得
    now_string = now.strftime("%Y/%m/%d %H:%M:%S")
    payload = {'serial_id': serialid, 'name': name, 'datetime': now_string, 'data': value}
    send_data(payload)
    slider.msg_log ("end sending...")
    slider.network_ok_report()
  except IOError:
#    slider.io_error_report()
    slider.network_io_error_report()
  except:
    slider.unknown_error_report()
Ejemplo n.º 5
0
def send(serialid, filepath, device):
  global ini, public_serialid
  try:
    slider.msg_log ( "start sending...")
    if ini.get("monitor", "mode") == "public":
      # public mode, so use public_serialid
      serialid = public_serialid
    now = datetime.datetime.now() # 時刻の取得
    now_string = now.strftime("%Y/%m/%d %H:%M:%S")
    files = {'upfile': open(filepath, 'rb')}
    payload = {'serial_id': serialid, 'device': device, 'datetime': now_string}
    send_data(payload, files)
#    comand_str = 'curl --insecure -k -F "upfile=@' + filepath + '" -F "serial_id='+serialid+ '" -F "device='+device+'" '+requests.post(ini.get("server", "url_base")) + 'postpic.php'+ '--retry 30'
#    print command_str
#    p = subprocess.check_call(command_str, shell=True)
    slider.msg_log ( "end sending...")
    slider.network_ok_report()
  except IOError:
#    slider.io_error_report()
    slider.network_io_error_report()
  except:
    slider.unknown_error_report()
Ejemplo n.º 6
0
def send(serialid, name, value):
    global ini, public_serialid
    try:
        slider.msg_log("start sending...")
        if ini.get("monitor", "mode") == "public":
            # public mode, so use public_serialid
            serialid = public_serialid
        now = datetime.datetime.now()  # 時刻の取得
        now_string = now.strftime("%Y/%m/%d %H:%M:%S")
        payload = {
            'serial_id': serialid,
            'name': name,
            'datetime': now_string,
            'data': value
        }
        send_data(payload)
        slider.msg_log("end sending...")
        slider.network_ok_report()
    except IOError:
        #    slider.io_error_report()
        slider.network_io_error_report()
    except:
        slider.unknown_error_report()
Ejemplo n.º 7
0
def save(serialid, device, picfilepath):
    try:
        slider.msg_log('start saving...')
        today = datetime.datetime.now() # 時刻の取得
        today_string = today.strftime("%Y%m%d")
        savedfilepath = data_path+'/'+device+'/'+today_string+'/'+os.path.basename(picfilepath)
        slider.msg_log('savedfilepath = '+savedfilepath)
        if_not_exist_then_make_folder(device, today_string)
        shutil.move(picfilepath, savedfilepath)
        slider.msg_log('end saving...')
    except IOError:
        slider.file_io_error_report()
    except:
        slider.unknown_error_report()
    slider.file_ok_report()
Ejemplo n.º 8
0
def save(serialid, name, value):
    try:
        slider.msg_log("start saving...")
        now = datetime.datetime.now() # 時刻の取得
        now_string = now.strftime("%Y/%m/%d %H:%M:%S")
        path = data_path+"/"+name+".csv"
        line = now_string+","+str(value)+","+serialid
        logfile = open(path, 'a')
        slider.msg_log(line)
        print >> logfile, line
        logfile.close()    
        slider.msg_log("end saving...")
    except IOError:
        slider.file_io_error_report()
    except:
        slider.unknown_error_report()
    slider.file_ok_report()
Ejemplo n.º 9
0
def save(serialid, name, value):
    try:
        slider.msg_log("start saving...")
        now = datetime.datetime.now()  # 時刻の取得
        now_string = now.strftime("%Y/%m/%d %H:%M:%S")
        path = data_path + "/" + name + ".csv"
        line = now_string + "," + str(value) + "," + serialid
        logfile = open(path, 'a')
        slider.msg_log(line)
        print >> logfile, line
        logfile.close()
        slider.msg_log("end saving...")
    except IOError:
        slider.file_io_error_report()
    except:
        slider.unknown_error_report()
    slider.file_ok_report()
Ejemplo n.º 10
0
                           json.JSONEncoder().encode(payload))
        slider.msg_log("by mqtt.")


#serialid = gs.get_serialnumber()
#msg_log("serialid=" + serialid)
#version  = gv.get_version()
#msg_log("version=" + version)

# mqtt
if ini.get("send", "protocol") == "mqtt":
    mqtt_id = ini.get("mqtt", "id_base") + serialid
    mqttclient = mqtt.Client(client_id=mqtt_id,
                             clean_session=True,
                             protocol=mqtt.MQTTv311)
    slider.msg_log("id = " + mqtt_id)
    #client.username_pw_set(USERNAME, PASSWORD)
    mqtt_host = ini.get("mqtt", "host")
    mqttclient.connect(mqtt_host)
    slider.msg_log("host = " + mqtt_host)


def send(serialid, filepath, device):
    global ini, public_serialid
    try:
        slider.msg_log("start sending...")
        if ini.get("monitor", "mode") == "public":
            # public mode, so use public_serialid
            serialid = public_serialid
        now = datetime.datetime.now()  # 時刻の取得
        now_string = now.strftime("%Y/%m/%d %H:%M:%S")
Ejemplo n.º 11
0
        r = requests.post(ini.get("server", "url_base") + 'postpic.php', data=payload, files=files, timeout=10, cert=os.path.dirname(os.path.abspath(__file__))+'/slider.pem', verify=False)
        slider.msg_log("by http.")
    elif ini.get("send", "protocol") == "mqtt":
        mqttclient.publish(ini.get("mqtt", "topic"), json.JSONEncoder().encode(payload))
        slider.msg_log("by mqtt.")

#serialid = gs.get_serialnumber()
#msg_log("serialid=" + serialid)
#version  = gv.get_version()
#msg_log("version=" + version)

# mqtt
if ini.get("send", "protocol") == "mqtt":
    mqtt_id = ini.get("mqtt", "id_base")+serialid
    mqttclient = mqtt.Client(client_id=mqtt_id, clean_session=True, protocol=mqtt.MQTTv311)
    slider.msg_log("id = " + mqtt_id)
    #client.username_pw_set(USERNAME, PASSWORD)
    mqtt_host = ini.get("mqtt", "host")
    mqttclient.connect(mqtt_host)
    slider.msg_log("host = " + mqtt_host)


def send(serialid, filepath, device):
  global ini, public_serialid
  try:
    slider.msg_log ( "start sending...")
    if ini.get("monitor", "mode") == "public":
      # public mode, so use public_serialid
      serialid = public_serialid
    now = datetime.datetime.now() # 時刻の取得
    now_string = now.strftime("%Y/%m/%d %H:%M:%S")
Ejemplo n.º 12
0
def read():
  ############################################################
  # sensors
  #
  slider.msg_log("read.py started.")

  # rtmpbroadcast 中ならスキップ
  if is_rtmpbroadcast():
    slider.msg_log("conflict with rtmpbroadcast")
    return False

  for sensor_name, sensor_settings in config["sensors"].items():
    slider.msg_log(sensor_name)

    # road reader.
    reader = importlib.import_module(sensor_name)
    try:
      value = reader.read()
    except IOError:
      slider.io_error_report()
      continue
    except:
      slider.unknown_error_report()
      continue

    if (value is not None):
      datas = sensor_settings['data']
      for data in datas:
        slider.msg_log(data[2])
        if data[2]: # Send
          # read specified sender.
          try:
            sender = importlib.import_module(data[2])
            sender.send(serialid, data[0], value[data[0]]) # serialid, name, value
          except IOError:
            slider.io_error_report()
          except:
            slider.unknown_error_report()
        slider.msg_log(data[3])
        if data[3]: # Save
          # read specified saver.
          try:
            saver = importlib.import_module(data[3])
            saver.save(serialid, data[0], value[data[0]]) # serialid, name, value
          except IOError:
            slider.io_error_report()
          except:
            slider.unknown_error_report()

  ############################################################
  # image
  #
  for imagedevice_name, data in config["imaging"].items():
    imagedevice_settings = data["data"]
    slider.msg_log( imagedevice_name)
    if imagedevice_name == 'uvc': # USB カメラなら
      devices = []
#      d = datetime.datetime.today()
#      now = d.strftime("%Y%m%d%H%M%S")
      if imagedevice_settings[1] == "one":
        devices = ["video0"]
      elif imagedevice_settings[1] == "all":
        # UVC カメラデバイスの数だけ
        devices = videodevices.videodevices_basename()
      elif imagedevice_settings[1] == "dummy":
        # dummy 画像の取得
        devices = ["video0"]

      for videodevice in devices:
        # rtmpbroadcast 中ならスキップ
        # if is_rtmpbroadcast():
        #   continue

        videodevice_now = datetime.datetime.today().strftime("%Y%m%d%H%M%S")
        filepath = '/tmp/'+videodevice_now+'.jpg'
        slider.msg_log( filepath)
        if imagedevice_settings[1] == "dummy":
#          command_str = 'fswebcam '+filepath+' -d TEST -r 320x240'
          command_str = os.path.dirname(os.path.abspath(__file__))+'/photographier.sh '+filepath+' dummy 320x240'
        else:
#          command_str = 'fswebcam '+filepath+' -d /dev/'+videodevice+' -D 1 -S 20 -r 320x240'
          command_str = os.path.dirname(os.path.abspath(__file__))+'/photographier.sh '+filepath+' '+videodevice+' 320x240'
        slider.msg_log( command_str)
        try:
          p = subprocess.check_call(command_str, shell=True)
          slider.msg_log ('p = ' + str(p))
        except IOError:
          slider.io_error_report()
          continue
        except:
          slider.unknown_error_report()
          continue

        if imagedevice_settings[2]: # Send
          # read specified sender.
          slider.msg_log(imagedevice_settings[2])
          try:
            sender = importlib.import_module(imagedevice_settings[2])
            sender.send(serialid, filepath, videodevice) # serialid, name, value
          except IOError:
            slider.io_error_report()
          except:
            slider.unknown_error_report()

        if imagedevice_settings[3]: # Save
          # read specified saver.
          slider.msg_log(imagedevice_settings[3])
          try:
            saver = importlib.import_module(imagedevice_settings[3])
            saver.save(serialid, videodevice, filepath) # serialid, device, picfilepath
          except IOError:
            slider.io_error_report()
          except:
            slider.unknown_error_report()

        # 撮影画像を move しなかった場合は明に削除
        if os.path.exists(filepath):
          os.remove(filepath)

  slider.msg_log("read.py ended.")
Ejemplo n.º 13
0
def read():
    ############################################################
    # sensors
    #
    slider.msg_log("read.py started.")

    # rtmpbroadcast 中ならスキップ
    if is_rtmpbroadcast():
        slider.msg_log("conflict with rtmpbroadcast")
        return False

    for sensor_name, sensor_settings in config["sensors"].items():
        slider.msg_log(sensor_name)

        # road reader.
        reader = importlib.import_module(sensor_name)
        try:
            value = reader.read()
        except IOError:
            slider.io_error_report()
            continue
        except:
            slider.unknown_error_report()
            continue

        if (value is not None):
            datas = sensor_settings['data']
            for data in datas:
                slider.msg_log(data[2])
                if data[2]:  # Send
                    # read specified sender.
                    try:
                        sender = importlib.import_module(data[2])
                        sender.send(serialid, data[0],
                                    value[data[0]])  # serialid, name, value
                    except IOError:
                        slider.io_error_report()
                    except:
                        slider.unknown_error_report()
                slider.msg_log(data[3])
                if data[3]:  # Save
                    # read specified saver.
                    try:
                        saver = importlib.import_module(data[3])
                        saver.save(serialid, data[0],
                                   value[data[0]])  # serialid, name, value
                    except IOError:
                        slider.io_error_report()
                    except:
                        slider.unknown_error_report()

    ############################################################
    # image
    #
    for imagedevice_name, data in config["imaging"].items():
        imagedevice_settings = data["data"]
        slider.msg_log(imagedevice_name)
        if imagedevice_name == 'uvc':  # USB カメラなら
            devices = []
            #      d = datetime.datetime.today()
            #      now = d.strftime("%Y%m%d%H%M%S")
            if imagedevice_settings[1] == "one":
                devices = ["video0"]
            elif imagedevice_settings[1] == "all":
                # UVC カメラデバイスの数だけ
                devices = videodevices.videodevices_basename()
            elif imagedevice_settings[1] == "dummy":
                # dummy 画像の取得
                devices = ["video0"]

            for videodevice in devices:
                # rtmpbroadcast 中ならスキップ
                # if is_rtmpbroadcast():
                #   continue

                videodevice_now = datetime.datetime.today().strftime(
                    "%Y%m%d%H%M%S")
                filepath = '/tmp/' + videodevice_now + '.jpg'
                slider.msg_log(filepath)
                if imagedevice_settings[1] == "dummy":
                    #          command_str = 'fswebcam '+filepath+' -d TEST -r 320x240'
                    command_str = os.path.dirname(
                        os.path.abspath(__file__)
                    ) + '/photographier.sh ' + filepath + ' dummy 320x240'
                else:
                    #          command_str = 'fswebcam '+filepath+' -d /dev/'+videodevice+' -D 1 -S 20 -r 320x240'
                    command_str = os.path.dirname(
                        os.path.abspath(__file__)
                    ) + '/photographier.sh ' + filepath + ' ' + videodevice + ' 320x240'
                slider.msg_log(command_str)
                try:
                    p = subprocess.check_call(command_str, shell=True)
                    slider.msg_log('p = ' + str(p))
                except IOError:
                    slider.io_error_report()
                    continue
                except:
                    slider.unknown_error_report()
                    continue

                if imagedevice_settings[2]:  # Send
                    # read specified sender.
                    slider.msg_log(imagedevice_settings[2])
                    try:
                        sender = importlib.import_module(
                            imagedevice_settings[2])
                        sender.send(serialid, filepath,
                                    videodevice)  # serialid, name, value
                    except IOError:
                        slider.io_error_report()
                    except:
                        slider.unknown_error_report()

                if imagedevice_settings[3]:  # Save
                    # read specified saver.
                    slider.msg_log(imagedevice_settings[3])
                    try:
                        saver = importlib.import_module(
                            imagedevice_settings[3])
                        saver.save(serialid, videodevice,
                                   filepath)  # serialid, device, picfilepath
                    except IOError:
                        slider.io_error_report()
                    except:
                        slider.unknown_error_report()

                # 撮影画像を move しなかった場合は明に削除
                if os.path.exists(filepath):
                    os.remove(filepath)

    slider.msg_log("read.py ended.")