help about PME sketch
Posted: 09 Sep 2020, 11:59
hi friends.
i am beginner in programming.
i want send a similar command with PME sketch :
i have an input specific data and i need Processing my data in arduino IDE , in the end send a command with PME sketch and espeasy (i2c).
in arduino nano : for example
how i can put this code in PME sketch ? i am use espeasy v2.0 and this sketch for PME :
Generally i want send a command to domoticz controller with arduino that arduino is connected to espeasy with an i2c . so arduino send command to esp8266 with i2c and esp8266 send command to controller.
thank you for help
i am beginner in programming.
i want send a similar command with PME sketch :
Code: Select all
SendToHTTP 192.168.1.200,8080,/json.htm?type=command¶m=switchlight&idx=91&switchcmd=Off
in arduino nano : for example
Code: Select all
if (my data)
SendToHTTP 192.168.1.200,8080,/json.htm?type=command¶m=switchlight&idx=91&switchcmd=Off
Code: Select all
#include <Wire.h>
#define I2C_MSG_IN_SIZE 4
#define I2C_MSG_OUT_SIZE 4
#define CMD_DIGITAL_WRITE 1
#define CMD_DIGITAL_READ 2
#define CMD_ANALOG_WRITE 3
#define CMD_ANALOG_READ 4
volatile uint8_t sendBuffer[I2C_MSG_OUT_SIZE];
void setup()
{
Wire.begin(0x7f);
Wire.onReceive(receiveEvent);
Wire.onRequest(requestEvent);
}
void loop() {}
void receiveEvent(int count)
{
if (count == I2C_MSG_IN_SIZE)
{
byte cmd = Wire.read();
byte port = Wire.read();
int value = Wire.read();
value += Wire.read()*256;
switch(cmd)
{
case CMD_DIGITAL_WRITE:
pinMode(port,OUTPUT);
digitalWrite(port,value);
break;
case CMD_DIGITAL_READ:
pinMode(port,INPUT_PULLUP);
clearSendBuffer();
sendBuffer[0] = digitalRead(port);
break;
case CMD_ANALOG_WRITE:
analogWrite(port,value);
break;
case CMD_ANALOG_READ:
clearSendBuffer();
int valueRead = analogRead(port);
sendBuffer[0] = valueRead & 0xff;
sendBuffer[1] = valueRead >> 8;
break;
}
}
}
void clearSendBuffer()
{
for(byte x=0; x < sizeof(sendBuffer); x++)
sendBuffer[x]=0;
}
void requestEvent()
{
Wire.write((const uint8_t*)sendBuffer,sizeof(sendBuffer));
}
thank you for help