Start a new topic

Is it possible to add Arduino to OpenEVSE v4?

Good day! I have OpenEVSE v4. Is it possible to additionally connect Arduino (UNO) and arrange data exchange between them? The garage where I charge the car is outside the WiFI network, so I want to connect the GSM module to the Arduino UNO and control the charging process via mobile communication. Is it possible? I need to know exactly the possibility of connecting OpenEVSE and Arduino. Thank you in advance for your cooperation!

Yes, OpenEVSE uses the same microprocessor as the Arduino UNO the Atmel 328p. So it basically the same as connecting two UNOs together.


The easiest way to connect is with serial, but you could also use SPI or I2C.




1 person likes this

Thank you!

I see connecting with Serial is the easiest, does the OpenEVSE has the sender code installed?

Hi,


Yes, instead of ESP, you can connect Arduino (via UART).


List of commands and responses available in OpenEVSE: https://github.com/lincomatic/open_evse/blob/development/firmware/open_evse/rapi_proc.h


On OpenEVSE UART speed = 115200 Baud

You can send commands to OpenEVSE like this: 

Serial.println("$GS"); - get the current state.

The command response can be from a tag ($OK or $NK on error), the response itself, and like a checksum.


An example of a response decryption (found somewhere on the OpenEVSE github):


 

   #define RAPI_SERIAL Serial // RAPI protocol set serial port (RX0 / TX0)
   #define RAPI_BUFLEN 13 // RAPI msg buffer size
   uint8_t EVSE_STATE = 0;

  // Class
  class RAPI {
    int m_RAPIinByte;
    char m_RAPIinstr[RAPI_BUFLEN];
    int m_RAPIstrCount;
  public:
    RAPI();
    void Init();
    void flush() {
      RAPI_SERIAL.flush();
    }
    void getInput();
    uint8_t getInt();
  };
  RAPI g_RAPI;

  // Function
  RAPI::RAPI()
  {
    m_RAPIstrCount = 0;
  }

  void RAPI::Init()
  {
   g_RAPI.flush();
  }

  uint8_t RAPI::getInt()
  {
    uint8_t c;
    uint8_t num = 0;
    do {
      c = RAPI_SERIAL.read(); // read the byte
      if ((c >= '0') && (c <= '9')) {
        num = (num * 10) + c - '0';
      }
    } while (c != 13);
    return num;
  }

  void RAPI::getInput()
   {
    if(RAPI_SERIAL.available()) { // if byte(s) are available to be read
      m_RAPIinByte = RAPI_SERIAL.read(); // read the byte
      //RAPI_SERIAL.print(char(m_RAPIinByte)); // Not use! $NK^21 in cycle
      if(m_RAPIinByte != 13) {
        m_RAPIinstr[m_RAPIstrCount] = char(m_RAPIinByte);
        m_RAPIstrCount++;
      }
      if(m_RAPIinByte == 13) {
		  
	  // Info msg
      if(strstr(m_RAPIinstr, "$ST") != NULL) {
         if(strstr(m_RAPIinstr, "$ST 00") != NULL) {
           EVSE_STATE = 0;			 
        }
        else if(strstr(m_RAPIinstr, "$ST 01") != NULL) {
          EVSE_STATE = 1;
        }
        else if(strstr(m_RAPIinstr, "$ST 02") != NULL) {
          EVSE_STATE = 2;
        }
        else if(strstr(m_RAPIinstr, "$ST 03") != NULL) {
          EVSE_STATE = 3;
        }
      }
	  
      // Respond msg
      else if(strstr(m_RAPIinstr, "$OK") != NULL) {
        // free
        if(strstr(m_RAPIinstr, "$OK 1 ") != NULL) {
          EVSE_STATE = 1;
        }
        // connected
        else if(strstr(m_RAPIinstr, "$OK 2 ") != NULL) {
          EVSE_STATE = 2;
        }
        // charging
        else if(strstr(m_RAPIinstr, "$OK 3 ") != NULL) {
          EVSE_STATE = 3;
        }
      }

      g_RAPI.flush();
      m_RAPIstrCount = 0; // get ready for new input... reset strCount
      m_RAPIinByte = 0; // reset the inByte variable
      for(int i = 0; m_RAPIinstr[i] != '\0'; i++) { // while the string does not have null
        m_RAPIinstr[i] = '\0'; // fill it with null to erase it
      }
     }
    }
   }

 

Login or Signup to post a comment