LoPy on corporate WiFi and using Tx/Rx commands **SOLVED**



  • Hi there, I'm new to the LoPy environment and have two questions.

    ps. I've succesfully upgraded my LoPy to the latest filmware and followed the basic steps to get my LoPy working (the stoplight example, in the examples section, provider by Pycom, is working :)) ... I can access my LoPy (with the Pycom Expansion Board) by direct serial-usb cable and by AP (Access Point/WiFi hotspot)

    Question 1:
    My next step (because I want to access my LoPy from a distance, and I'm not ready yet to use lora) is to connect the LoPy by WiFi (Corporate WiFi). I can manage this, but how do you find the LoPy back in the wireless network?
    For example, when I use the Pymkr IDE, how can I connect to/find the LoPy when it's in 'the cloud'? I can imagine you use an unique IP number, but when it's dynamic, the IP changes. Or perhaps do you use the unique LoPy name or perhaps a MAC Address?
    My goal will be a couple of LoPy's in a corporate WiFi with one manage tool. The manage tool will be webbased and programmed by html/python (custom made).

    Question 2:
    Are there any examples out there, or perhaps people with experience that succesfully used the UART of the LoPy?
    I want to transmit (hard connection/wiring) Tx (serial data) commands to the LoPy. Also Rx data is important for my. But first the basics ;-)

    I hope someone can help me out, or point me in the right direction... With kind regards, Jeroen Wolf (from the Netherlands)



  • Hi livius, Hi jmarcelino,

    Thx for your tips... Great news (at least for me ;-)), the first step in my end goal is working :-)

    alt text

    It is now possible for me to turn on a projector (or any other command(s)) via WiFi using the LoPy and the MAX3232 board.

    For reference and other people interested this is the code for main.py... (boot.py is unaltered)

    from machine import UART
    projector = UART(1)
    projector.init(baudrate=9600, bits=8, parity=None, stop=1)
    projector.write('POWR 1\r')

    from machine import Pin
    led = Pin("G16", mode=Pin.OUT)
    button = Pin("G17", mode=Pin.IN, pull=Pin.PULL_UP)

    while True:
    led(button())

    Next step will be:

    • A (couple of) button(s) hard wired directly to the LoPy to give more functionality.
    • Read out projector status (lamp hours, active input, etc.) and doing something with this info.
    • Implement the LoPy on the corporate open WiFi network and finding the LoPy back.
    • Using LoRa instead of WiFi in a point-to-point configuration (I preferer this over WiFi).
    • Design/program a webbased managing tool to control lots (max 100) devices.


  • The way @livius wrote is the most generic way but because 0x0D is a carriage return in ASCII you can just use \r at the end of the string.



  • @joena

    to write letters e.g. "HI"

    uart.write(bytes([0x48,0x49]))
    


  • Totday the MAX3232 breakout box arrived and serial data is succesfully sent to the rs232 port :-) So great (I used a free dataviewer tool, from Extron to check this). Only one question:
    I can sent the ASCII Power ON commando, but after each command I have to sent the execute code to the projector, this is the hex command: %0D (for our type projector). What syntax in python is correct to accomplish this? I used these lines:

    from machine import UART
    lcd_projector = UART(1)
    lcd_projector.init(9600, bits=8, parity=None, stop=1)
    lcd_projector.write('POWR 1')

    I can see the correct code (if I use the data viewer), but the problem is that the code isn't executed. Can I use ASCII and HEX in one line??

    If I hard code append it, the projector sees this as a sort of variable/string.. This is not correct

    Grts, Jeroen



  • @jmarcelino
    @bucknall

    Just to inform, i will be testing it not today, but tomorrow (today I've ordered the max3232 unit), hope it arrives tomorrow ;)



  • @joena
    yes that should do it!

    Let us know how it goes :)



  • @jmarcelino alt text

    Something like this jmarcelino? The VCC would be the 3.3Vout of the LoPy. The chip is the MAX3232.

    Grts, Jeroen



  • @jmarcelino

    Aah thx jmarcelino, I will keep this in mind. Thx for this pointer, jeroen

    http://www.radio-electronics.com/info/telecommunications_networks/rs232/signals-voltages-levels.php

    I learned something today :-)



  • @bucknall

    Hi bucknall, thx so much for your quick answer/response. Yes i want to control the projector with the LoPy ;-) for now Tx signals/commands are great, if all works out I want to implement Rx to read out projector status, like lamp hours, on/off status, etc.

    Your response looks promising .. I will implement it tomorrow at work (I just got out of work ;-))

    I will let you/the community know if it worked :-) thx for now, Jeroen



  • @joena

    To add to @bucknall's reply, the UART connections will give you 3.3 volt level serial however true RS-232 - what most projectors expect - use up to +15/-15V levels so you'll need an extra driver chip like the MAX3232.

    If you look on Ebay you can find many cheap MAX3232 modules. Then connect your LoPy UART to those and from there to your projector.


  • administrators

    Hi @joena,

    Absolutely! So let me just confirm - You wish to control an LCD projector via rs232 from the LoPy?

    You can do this using the UART class:

    from machine import UART
    lcd_projector = UART(1) 
    
    lcd_projector.init(9600, bits=8, parity=None, stop=1) # you may need specific options
    lcd_projector.write(your_data)
    

    You will need to ensure that your wiring goes between TX & RX [P3/P4 (lopy), G11/G24 (expansion board)] to your projector

    Let me know how that goes!



  • @bucknall

    Hi Bucknall, thx for your reply ... :)
    When reading my original post I forgot to mention something essential (for question 2). I don't want to control the LoPy via another device, I want the LoPy to control another device (a lcd projector).

    What is the easiest method to sent a hex code via Tx (rs232) to my projector using a LoPy?

    I hope you can help me out, or point me into the right direction...
    In your example I saw lorawan, but If I want to do it using UART is this also possible?

    Tx:
    my ascii code is: POWR 1%0D
    the hex code is: 50 4F 57 52 20 20 20 31 0D

    With kind regards, Jeroen



  • for your reply livius :)


  • administrators

    Hi @joena,

    What I normally do, is place a snippet of code at the end of my boot.py -

    wlan.ifconfig()
    

    This tells me what the IP address of my device when it has connected to my WiFi network.

    You can also set a static IP address for the device so it's the same everytime you connect to the network.

    (https://docs.pycom.io/pycom_esp32/pycom_esp32/tutorial/includes/wlan.html#assigning-a-static-ip-address-when-booting)

    Question 2:

    Yes! I've recently been talking to the LoPy from a Raspberry Pi (https://github.com/Bucknalla/lopy-raspberrypi) I need to push this code to the documentation but it's a fairly straightforward process. Just make sure that you wire the TX & RX correctly! :)

    Let me know how you get on with this!

    Cheers,

    Alex



  • @joena said in LoPy on corporate WiFi and using Tx/Rx commands:

    Question 1:

    this can point to two scenarios

    1. All lopys connect to server and i can think that this is the basic and simplest scenario
      and work without any problem - you do not find them only them find you ;-)
    2. If your tool need to find them than basic steep is to set all Lopy unique but prefixed name (maybe default is ok for you) and then after connection you can add some autorization. You can of course use fixed mac list but if this is for developing purpose then use simplest posible way for you.

    HINT - Do not use Pymakr at all
    https://forum.pycom.io/topic/635/pymakr-time-of-death-09-02

    Question 2:
    use standard documentation for uart
    https://docs.pycom.io/pycom_esp32/library/machine.UART.html

    • it work for me without problem - but i do not use flow control
      i read somwhere on the forum that flow control not work properlyu and i do not know i it is fixed now

Log in to reply
 

Looks like your connection to Pycom Forum was lost, please wait while we try to reconnect.