Запросы, различающиеся по скорости между различными языками и устройствами

#java #windows #python-requests #raspberry-pi #philips-hue

Вопрос:

Я пытался выполнить несколько команд для Philips hue lights через библиотеку python phue — https://github.com/studioimaginaire/phue. Проблема, с которой я столкнулся, заключается в том, что на устройстве Windows каждый запрос может занимать 5-6 секунд,

 # PYTHON

import time
from phue import Bridge

# Find and connect to bridge
b = Bridge('<Hue Bridge IP>')
b.connect()

# This takes 5-6 seconds per
b.set_group(1, 'on', True)
# Also it does not matter if it a singular light or a group of lights
b.set_group(1, 'hue', 7000)
 

Я попытался покинуть библиотеку phue и заменить ее чистыми запросами, как показано здесь:

 # PYTHON

# URL
url = "<The Hue API URL   Key   Specifications>"

# Body
data_on = {"on":True, "sat":254, "bri":254,"hue":c}
data_off = {"on":False}

# Occasionally exceeds this timeout
r = requests.put(url, json.dumps(data_on), timeout=5)
 

Затем я попытался выполнить аналогичную команду на java, используя библиотеку ZeroOne3010 здесь — https://github.com/ZeroOne3010/yetanotherhueapi (yetanotherhueapi или yahueapi), пример сценария здесь:

 // JAVA

// Colours
java.awt.Color red = new java.awt.Color(255, 0, 0);

// Find Room   Bridge
final String bridgeIp = <IP>;
final String apiKey = <KEY>;
final Hue hue = new Hue(bridgeIp, apiKey);
final Room room = hue.getRoomByName("<ROOM NAME>").get();

// Find Light   Set to red and on
Light light1 = room.getLightByName("<LIGHT NAME>").get();
light1.setState(State.builder().color(Color.of(red)).on());
 

И это выполняется менее чем за секунду в несколько раз быстрее, чем в python с запросами или предыдущей библиотекой, так что на данный момент кажется, что проблема здесь в python, но нет?

Затем я загрузил raspberry pi и запустил оба предыдущих сценария python, и они выполнялись с такой же задержкой, как и запрос java к API hue

So to my question how or why does this happen and more importantly is there a way to prevent this? I can’t find what exactly is the weak point, windows can make requests quickly python can make requests quickly but sometimes just won’t.

Extra Info about both devices

Connection:

  • Ras Pi is has no ethranet and has a lower up down and higher ping than the PC im running the python and java on/
  • PC is using an Ethernet cable/ Wired Connection

OS / Models:

  • Ras Pi 4 (4GB RAM) running rasbian OS 32 bit
  • Windows 10 no method of connecting other than a wired connection (much higher specifications than the pi)

Python Versions:

  • Ras Pi 4 runs 3.8
  • PC runs 3.9 by default and has 3.7 2.7 Installed

Both use venv as a virtual environment with no anaconda installation.

I have been thinking it might be something to do with the firewall but upon searching it I receive page after page of the practically identical article of how to speed up internet in windows.

This cannot be the issue as the PC has a faster connection.

Итак, есть какие-нибудь идеи? — Извините, если я пропустил что-то важное. (Краткое примечание дооснащение, которое предназначено для java — https://square.github.io/retrofit/ также находится в диапазоне одной секунды, и оба pi и ПК находятся в пределах метра друг от друга) Кроме того, я пытался запустить это за пределами моей IDE (PyCharm), как на pi, так как я запускаю его там в терминале, но безуспешно, имея его внутри CMD.