Я играл с примером WifisendTest, и это работает, но мне вручную нужно выбрать изображение и вручную вручную Отправить его.
Я хочу сделать этот шаг к сценарию Python, который выполняет работу.
он должен будет отобразить QR -код, который я автоматически создаю через другой скрипт Python. < /p>
У меня уже есть этот код: < /p>
Код: Выделить всё
import requests
from PIL import Image
import numpy as np
# Device IP Address
DEVICE_IP = "10.13.100.100"
UPLOAD_URL = f"http://{DEVICE_IP}/"
SHOW_URL = f"http://{DEVICE_IP}/SHOW_"
# Convert image to 1-bit array (packed bit array)
def convert_image(image_path):
img = Image.open(image_path).convert("1") # Convert to 1-bit monochrome
img = img.resize((200, 200)) # Ensure size is correct
img_data = np.array(img, dtype=np.uint8) # Convert to NumPy array
img_data = np.packbits(img_data) # Pack bits into bytes
return img_data
# Encode the image data to a custom format (no base64, just raw packed bits)
def encode_image_data(img_data):
encoded_data = "".join(chr(byte) for byte in img_data)
return encoded_data
# Upload the image to the device
def upload_image(image_path):
img_data = convert_image(image_path)
encoded_data = encode_image_data(img_data)
# Send the encoded data
response = requests.post(UPLOAD_URL + encoded_data + "LOAD_", headers={"Content-Type": "text/plain"})
print("Upload Response:", response.status_code, response.text)
# Send the SHOW command to refresh the display
show_response = requests.post(SHOW_URL)
print("Show Response:", show_response.status_code, show_response.text)
# Run the script
if __name__ == "__main__":
# Example image path
image_path = "BarCode.bmp"
upload_image(image_path)
< /code>
Этот скрипт выходит из строя. Timing Out ...
als попробовал это: < /p>
import requests
from PIL import Image
import numpy as np
import base64
# Device IP Address
DEVICE_IP = "10.13.100.100"
UPLOAD_URL = f"http://{DEVICE_IP}/"
SHOW_URL = f"http://{DEVICE_IP}/SHOW_"
# Convert image to 1-bit array
def convert_image(image_path):
img = Image.open(image_path).convert("1") # Convert to 1-bit monochrome
img = img.resize((200, 200)) # Ensure size is correct
img_data = np.array(img, dtype=np.uint8) # Convert to NumPy array
img_data = np.packbits(img_data) # Pack bits into bytes
return img_data
# Encode the image for transmission
def encode_image_data(img_data):
encoded_data = ""
for byte in img_data:
encoded_data += chr((byte & 0xF) + 97) # Convert to ASCII character encoding
encoded_data += chr(((byte >> 4) & 0xF) + 97)
return encoded_data
# Upload the image to the device
def upload_image(image_path):
img_data = convert_image(image_path)
encoded_data = encode_image_data(img_data)
# Send the encoded data
response = requests.post(UPLOAD_URL + encoded_data + "LOAD_", headers={"Content-Type": "text/plain"})
print("Upload Response:", response.status_code, response.text)
# Send the SHOW command to refresh the display
show_response = requests.post(SHOW_URL)
print("Show Response:", show_response.status_code, show_response.text)
# Run the script
if __name__ == "__main__":
image_path = "BarCode.png"
upload_image(image_path)
Подробнее здесь: https://stackoverflow.com/questions/794 ... ugh-python