All Projects → yozik04 → nextion

yozik04 / nextion

Licence: LGPL-3.0 license
Nextion serial client

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to nextion

Pyserial Asyncio
asyncio extension package for pyserial
Stars: ✭ 150 (+971.43%)
Mutual labels:  serial, asyncio
prisma-client-py
Prisma Client Python is an auto-generated and fully type-safe database client designed for ease of use
Stars: ✭ 739 (+5178.57%)
Mutual labels:  asyncio
spinach
Modern Redis task queue for Python 3
Stars: ✭ 46 (+228.57%)
Mutual labels:  asyncio
netunnel
A tool to create network tunnels over HTTP/S written in Python 3
Stars: ✭ 19 (+35.71%)
Mutual labels:  asyncio
py3tftp
An asynchronous TFTP server in pure Python 3.5
Stars: ✭ 39 (+178.57%)
Mutual labels:  asyncio
helo
A simple and small low-level asynchronous ORM using Python asyncio.
Stars: ✭ 18 (+28.57%)
Mutual labels:  asyncio
tomodachi
💻 Microservice library / framework using Python's asyncio event loop with full support for HTTP + WebSockets, AWS SNS+SQS, RabbitMQ / AMQP, middleware, etc. Extendable for GraphQL, protobuf, gRPC, among other technologies.
Stars: ✭ 170 (+1114.29%)
Mutual labels:  asyncio
think-async
🌿 Exploring cooperative concurrency primitives in Python
Stars: ✭ 178 (+1171.43%)
Mutual labels:  asyncio
fastapi-etag
Convenience library for working with etags in fastapi
Stars: ✭ 19 (+35.71%)
Mutual labels:  asyncio
showdown-battle-bot
Socket Battle Bot for Pokemon Showdown (http://pokemonshowdown.com/)
Stars: ✭ 19 (+35.71%)
Mutual labels:  asyncio
ParadoxRs232toMqtt
esp8266, serial bus to mqtt for Paradox alarm systems
Stars: ✭ 66 (+371.43%)
Mutual labels:  serial
callosum
An RPC Transport Library for asyncio
Stars: ✭ 17 (+21.43%)
Mutual labels:  asyncio
SerialToTCPBridgeProtocol
An error tolerant serial UART to TCP connection, raw data bridge.
Stars: ✭ 16 (+14.29%)
Mutual labels:  serial
waspy
WASP framework for Python
Stars: ✭ 43 (+207.14%)
Mutual labels:  asyncio
rearq
A distributed task queue built with asyncio and redis, with built-in web interface
Stars: ✭ 81 (+478.57%)
Mutual labels:  asyncio
pydf
PDF generation in python using wkhtmltopdf for heroku and docker
Stars: ✭ 68 (+385.71%)
Mutual labels:  asyncio
aioredis-cluster
Redis Cluster support extension for aioredis
Stars: ✭ 21 (+50%)
Mutual labels:  asyncio
aioredis-lock
Distributed locking implementation for aioredis
Stars: ✭ 20 (+42.86%)
Mutual labels:  asyncio
glacier
❄️ Building Python CLI using docstrings and typehints 🐍
Stars: ✭ 84 (+500%)
Mutual labels:  asyncio
synchronicity
Synchronicity lets you interoperate with asynchronous Python APIs.
Stars: ✭ 41 (+192.86%)
Mutual labels:  asyncio

Nextion serial client Build

Lightweight Python 3.6+ async library to control Nextion displays.

Installation

Pypi

pip3 install nextion

Simple usage:

import asyncio
import logging
import random

from nextion import Nextion, EventType

class App:
    def __init__(self):
        self.client = Nextion('/dev/ttyS1', 9600, self.event_handler)
    
    # Note: async event_handler can be used only in versions 1.8.0+ (versions 1.8.0+ supports both sync and async versions)
    async def event_handler(self, type_, data):
        if type_ == EventType.STARTUP:
            print('We have booted up!')
        elif type_ == EventType.TOUCH:
            print('A button (id: %d) was touched on page %d' % (data.component_id, data.page_id))
    
        logging.info('Event %s data: %s', type, str(data))
        
        print(await self.client.get('field1.txt'))
    
    async def run(self):
        await self.client.connect()
    
        # await client.sleep()
        # await client.wakeup()
    
        # await client.command('sendxy=0')
    
        print(await self.client.get('sleep'))
        print(await self.client.get('field1.txt'))
    
        await self.client.set('field1.txt', "%.1f" % (random.randint(0, 1000) / 10))
        await self.client.set('field2.txt', "%.1f" % (random.randint(0, 1000) / 10))
        
        await self.client.set('field3.txt', random.randint(0, 100))
    
        print('finished')

if __name__ == '__main__':
    logging.basicConfig(
        format='%(asctime)s - %(levelname)s - %(message)s',
        level=logging.DEBUG,
        handlers=[
            logging.StreamHandler()
        ])
    loop = asyncio.get_event_loop()
    app = App()
    asyncio.ensure_future(app.run())
    loop.run_forever()

Nextion constructor parameters

url: str # serial dev
baudrate: int # baud rate
event_handler: typing.Callable[[EventType, any], None] # Event handler function
loop=asyncio.get_event_loop() # your own event loop
reconnect_attempts: int = 3 # how many times to try to retry command in case of failure
encoding: str = 'ascii' # Nextion encoding

Nextion parameters

Encoding

You can update encoding on fly (This changes encoding of serial communication only):

client.encoding = 'latin-1'

Get current set encoding (Not fetched from the device)

print(client.encoding)

Event handling

event_handler method in the example above will be called on every event comming from the display.

EventType Data Data attributes
TOUCH TouchDataPayload page_id, component_id, touch_event
TOUCH_COORDINATE TouchCoordinateDataPayload x, y, touch_event
TOUCH_IN_SLEEP TouchCoordinateDataPayload x, y, touch_event
AUTO_SLEEP None -
AUTO_WAKE None -
STARTUP None -
SD_CARD_UPGRADE None -

For some components in the Nextion Editor you need to check Send Component ID for required event.

Firmware uploading

If you installed the library you should have nextion-fw-upload command in your PATH.

nextion-fw-upload -h

Otherwise use next command in the root of the project:

python -m nextion.console_scripts.upload_firmware -h

Usage (check with option -h)

usage: nextion-fw-upload [-h]
                         [-b {2400,4800,9600,19200,38400,57600,115200,230400}]
                         [-ub {2400,4800,9600,19200,38400,57600,115200,230400}]
                         [-v]
                         device file

positional arguments:
  device                device serial port
  file                  firmware file *.tft

optional arguments:
  -h, --help            show this help message and exit
  -b {2400,4800,9600,19200,38400,57600,115200,230400}, --baud {2400,4800,9600,19200,38400,57600,115200,230400}
                        baud rate
  -ub {2400,4800,9600,19200,38400,57600,115200,230400}, --upload_baud {2400,4800,9600,19200,38400,57600,115200,230400}
                        upload baud rate
  -v, --verbose         output debug messages

Additional resources:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].