Currently I am working with esp01 powered from Arduino uno and I am using MQTT protocol
I tried the to publish data to thingspeak cloud using the AT commands so I start connecting to the Wi-Fi and send first the connect frame and esp respond with "SEND OK" and then I send the publish frame and it respond with "SEND OK" as well BUT data didn't reach the cloud.
I tried before the http and everythung works fine but i am not sure what is wrong could it be a powering issue?
is someone can help me to find the problem
void Wifi_init(void){
//Set_Bit(SREG,SREG_I);
Enable_RXInterrupt();
UART_RX_SetCallBack(interrupt_func);
data_ready=0;
buff_lenght=0;
memset(receive_buffer,0,300); //reset buffer ,but 0 to all buffer elements
UART_SendString("AT+RST\r\n"); //reset wifi module
while (response_success("OK")!=OK);
_delay_ms(100);
UART_SendString("ATE0\r\n"); //disable echo
while (response_success("OK")!=OK);
_delay_ms(100);
UART_SendString("AT+CWMODE=3\r\n"); //Wifi mode 1--station,2--AP,3--station+AP
while (response_success("OK")!=OK);
_delay_ms(100);
UART_SendString("AT+CIPMUX=0\r\n"); //single connection mode
while (response_success("OK")!=OK);
_delay_ms(100);
UART_SendString("AT+CIPMODE=0\r\n"); //transfer mode 0--normal mode,1--wifi pass-through mode
while (response_success("OK")!=OK);
_delay_ms(100);
UART_SendString("AT+CWJAP=\"VodafoneMobileWiFi-3ABC36\",\"6996086485\"\r\n"); //connect to APs
while (response_success("OK")!=OK);
_delay_ms(100);
UART_SendString("AT+CIPSTART=\"TCP\",\"mqtt3.thingspeak.com\",1883\r\n"); //connect to the raspberry pi
while (response_success("OK")!=OK);
_delay_ms(1000);
}
}
void CONNECT (void){
uint8 remaining_length=16+23+23+24;
UART_SendString("AT+CIPSEND=88\r\n");
while (response_success("OK")!=OK);
_delay_ms(100);
UART_SendChar(0x10); //control field
UART_SendChar(0x56); //0x56 //remaining length
UART_SendChar(0x00); //protocol name length
UART_SendChar(0x04);
UART_SendString("MQTT");
UART_SendChar(0x04); //protocol level
UART_SendChar(0xC2); //connect flag (means the payload doesn't have a user name or a password and sessions are cleared)
UART_SendChar(0x00); //keep alive
UART_SendChar(0x3C);
UART_SendChar(0x00); // client id length
UART_SendChar(0x17);
UART_SendString("AQIJOwYtAzkqJSkQEQQ3Bxg"); //client id
UART_SendChar(0x00);
UART_SendChar(0x17);
UART_SendString("AQIJOwYtAzkqJSkQEQQ3Bxg");
UART_SendChar(0x00);
UART_SendChar(0x18);
UART_SendString("hSxegr0GjrvuxUHtzHmBeozg");
while (response_success("SEND OK")!=OK);
while (response_success("+IPD")!=OK);
}
void PUBLISH (uint8 * Topic,uint8 * data){
uint8 topic_bytes = strlen(Topic);
uint8 data_bytes = strlen(data);
uint8 frame_string [3];
uint8 send_command[20];
uint8 topic_length =string_length_hex(Topic);
uint8 data_length =string_length_hex(data);
UART_SendString("AT+CIPSEND=44\r\n"); //send the command
while (response_success("OK")!=OK);
_delay_ms(200);
///////CHECK THE RESPONSE
UART_SendChar(0x30); //protocol name length
UART_SendChar(0x2A); //44
UART_SendChar(0x00);
UART_SendChar(0x26);
UART_SendString((char *)Topic);
UART_SendString((char *)data);
while (response_success("SEND OK")!=OK);
_delay_ms(200);
}
int main(){
Set_Bit(SREG,SREG_I);
Dio_init();
USART_init();
Wifi_init();
CONNECT();
while(1){
PUBLISH("channels/1966346/publish/fields/field1","42");
_delay_ms(2000);
}
}