Wifi and mqtt on the rs9113

From wiki.emacinc.com
Revision as of 15:31, 6 June 2018 by Dsojka (talk | contribs) (Created page with "{{#seo: |title=Micropython |titlemode=append |keywords=Micropython |description=The following page can be used to get familiarized with Micropython on EMAC products. }} <!-- /...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The RS9113 family of modules are ultra-low power radio modules that support wifi, Bluetooth, and ZigBee. Emac has developed driver support for these modules in Micropython.

General Information


Class RS9113:

  • This class provides the driver for the RS9113 module through the SPI interface. It is imported from the 'network' module. The following is an example usage:
  • import network
    nic = network.RS9113(pyb.SPI(1), pyb.Pin("A4"), pyb.Pin("D9"), pyb.Pin("D10"))
    nic.connect('SSID', 'Password')


    network.RS9113(spi, pin_cs, pin_rst, pin_irq)
  • This constructor creates the RS913 object and initializes the module given the SPI bus and pins. Returns the RS9113 object. Arguments are:
    • spi a Micropython SPI object.
    • pin_cs a Micropython Pin object connected to the RS91113 module's Chip Select pin.
    • pin_rst a Micropython Pin object connected to the RS91113 module's Reset pin.
    • pin_irq a Micropython Pin object connected to the RS91113 module's Interrupt pin.
    • All arguments are initialized by the driver, so there is no need to initialize them manually.


  • RS9113.connect(ssid, key=None,*,security=WPA2, ssl=False, nonblocking=False)
  • Connects to the given SSID and security paramaters. If 'ssl' is set to True, all of the sockets created will be set to use SSL. If 'nonblocking' is set to True, all sockets will use nonblocking functionality.
  • RS9113.disconnect()
  • Disconnects from the WiFi network.
  • RS9113.isconnected()
  • Returns a True if connected to a network, False otherwise.
  • RS9113.sleep()
  • Puts the RS9113 module into deep (disconnected) sleep mode. This function is best called after the board is reset, so re-initializing the class should be done before calling sleep.

nic = network.RS9113(pyb.SPI(1), pyb.Pin("A4"), pyb.Pin("D9"), pyb.Pin("D10")) nic.sleep()

  • RS9113.ifconfig()
  • Returns a 4-tuple with (ip address, subnet mask, gateway, MAC address). This method requires the module to be successfully connected to a network.
  • RS9113.macaddr()
  • Returns a string containing the MAC address for the module. The string is colon separated octets without leading '0x.'
  • RS9113.scan()

Returns a list of 4-tuples with (SSID, RSSI value, security mode, RF channel, BSSID)

  • RS9113.fwap(ssid=None)

Warning: It is not necessary to use this under normal cirumstances.

Intended to be run directly after initialization of the module. This method puts the module into AP mode so that a firmware upgrade is possible. The ssid argument can be supplied to define the name of the access point. To upgrade the firmware: Run the fwap() method Connect to the access point. In a browser, navigate to the board's IP address. Click on the "Administration" tab. Click "Choose File", select the desired firmware file Click upgrade The REPL will show the progress and will display a completion message when done.

Power cycle the board.


RS9113.WPA2 RS9113.OPEN Security types to be used in RS9113.scan() and returned in a tuple with RS9113.scan().

Information regarding sockets can be found in the Micropython documentation. Once the RS9113 is initialized and connected, the socket module will use it without prompting. http://docs.micropython.org/en/v1.8.7/pyboard/library/usocket.html?