Code Monkey home page Code Monkey logo

esp32-rmt-server's Introduction

ESP32-RMT-server

WiFi server that drives low-level commands to the ESP32 RMT peripheral

NOTE: This code seems to work reliably and has all the features that I plan to implement. It is released.

The ESP32 receives an HTTP POST request and decodes commands contained in the request body. These commands control the RMT peripheral and drive an infrared LED. The commands are low-level mark and space commands. There is no protocol decode implemented in this application. This allows the RMT to transmit virtually any infrared protocol. Compiles with ESP-IDF

  • The HTTP POST request body consists of one or more text lines. Lines are separated by newline (\n) characters. Returns (\r) are allowed, but are ignored.
  • Each line consists of comma-separated values. There is one command on each line. Each line starts with one character that identifies the type of command for this line.

The intent is that a JavaScript program contained in an HTML file, running on a web browser and served by a host machine (not the ESP32) will create these low-level RMT commands and transmit them to the ESP32. An example HTML file is part of this repository. A real application will have its own repository.

Commands

The commands closely follow the RMT register/RAM definitions. Refer to the ESP32 documentation at http://esp32.net/ . Lines that do not follow these specifictions are silently ignored and the next line is processed.

  • c,[div],[high],[low]
    • Sets the RMT channel clock frequency and the carrier clock frequency and duty cycle.
    • [div]: RMT channel clock divider (RMT_DIV_CNT_CHn). Text representation of an integer between 1 and 255, inclusive. Defines the RMT channel clock division ratio. The channel clock is divided from the source clock. The ESP32 source clock is 80MHz.
    • [high] and [low]: High (RMT_CARRIER_HIGH_CHn) and low (RMT_CARRIER_LOW_CHn) duration of the carrier waveform. Text representation of integers between 1 and 65,535, inclusive. The unit of carrier_high/low is one source clock period.
  • t,[non-zero duration], ... ,0
    • Defines a sequence of durations of IR transmission bits, both modulated at the carrier frequency (mark) and idle (space).
    • [non-zero duration]: A text representation of a non-zero integer between -32,767 and 32,767, inclusive. These integers define the durations of transmit marks and spaces. A zero value denotes the end of the transmission sequence.
      • Positive integers create a burst of IR output (mark) at the carrier frequency, with duration of [non-zero-duration] channel clock periods.
      • Negative integers create a duration on the IR output with no carrier (space). The duration is in channel clock periods.
      • Positive and negative values do not need to be alternated. Either positive or negative values can follow a positive or negative value.
    • A zero value tells the RMT to stop the RMT transmission sequence. The last value on the line must be a zero. A zero anywhere else on the line will terminate the transmission sequence at that point. When terminated, a new RMT transmission can be started with a new command on a new line. There will be an indeterminate delay between consecutive RMT transmissions.
    • The RMT RAM can store a maximum of 128 duration values. If a line contains more than 128 values, the driver implements the RMT wrap-around mode to transmit the longer sequence. The terminating zero duration counts as one of the duration values.
  • d,[milliseconds delay]
    • [milliseconds delay]: Create a delay before decoding the next line. Used to create a realtively long gap between IR tramsmissions. Text representation of a positive non-zero integer of the number of milliseconds for the delay. Implemented with the FreeRTOS function:
      • vTaskDelay( milliseconds delay / portTICK_PERIOD_MS ); and has the limitations of that function. See the documentation for this function for the maximum possible delay, which depends on the tick period of your system and the data type used for this function. If your tick period is 1mS and the data type uses a 16-bit unsigned int, the maximum duration is about 65 seconds.

Definitions

  • HTTP POST Request: A combination of request header and request body, sent to the ESP32. Your web browser automatically inserts a blank line between the header and body.
  • Request Header: Your browser creates most of this. Important options for this application are:
    • Request Type: POST. Needed to avoid CORS restrictions and to contain enough information for the ESP32.
    • Content-Type: text/plain. Needed to avoid CORS restrictions.
  • Request Body: One or more lines of text, following the format described above.
  • Lines: In this application, each line in the request body consists of multiple text values, separated by commas. All of the numbers transmitted to the ESP32 are text representations of decimal numbers. Each line is terminated by either:
    • a newline (\n), or
    • a return (\r) and a newline (\n), or
    • the end of the request body
  • Same-Origin-Policy: Keeps your compliant browser from fetching information from a different server than the original web page was served from. This is an important internet security feature.
  • CORS: Cross-Orgin-Resource-Sharing. A complex way to allow communications between different web hosts. This is the authorized way to skirt the Same-Origin-Policy. See the WiKi for more information.

esp32-rmt-server's People

Contributors

kimeckert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

esp32-rmt-server's Issues

How to question: Transmit ONLY

I'm trying to use an ESP32 with IR emitter / receiver as a tachometer. I want to use the RMT function to blink the LED at 38kHz, and searching for how to do that has led me to this project. Hopefully this is a quick and easy question for you. If all I want to do is blink the LED at 38kHz, it looks like the only parts of your code I need are:

// RMT values
#define RMT_TX_CHANNEL RMT_CHANNEL_0
#define RMT_TX_GPIO    GPIO_NUM_26
// channel clock period = 1 uS
#define RMT_CLK_DIV    80

and your rmt_tx_ini() function, which I would call in the setup section of my Arduino sketch.

Does that seem correct? Thanks so much - I know you're done with this project, but it's the best example I've found of what I think I want to do, so I hope you see this, and can give a quick answer.

Not an issue, a question: RMT_CLK_DIV 100 or 80?

This rocks!

Just a question, looking back at rmt_nec_tx_rx - why did you modify RMT_CLK_DIV from 100 to 80?
For my remote I had to set it to 100 so it would work.

I guess that means the interval is 0.8us and not 1us?

HTTP Requests don't support (right now) fragments

Hi,

I've deployed the project on my ESP units. Seems that when transmitting lengthy 't,' code lines -- the code fetch only first fragment. I had to modify the code on both server and web client page side to support multiple fragments calls to the server.

Very well done, nonetheless... excellent!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.