He comenzado a trabajar en HLK-m30 módulo WiFi. Estoy desarrollando el cliente simple en el módulo usando comandos AT simples. He abierto el cliente TCP de socket y luego escribo datos usando el comando.
GET / HTTP/1.1
Host: www.google.com
cuando leo socket usando AT comando me muestra 0: ok. mientras que 0 es el número de Socket y ok es la respuesta del comando pero no recibe ningún dato.
Tampoco puedo hacerlo funcionar en modo de transmisión transparente.
cuando estoy leyendo Socket consulta, utilizando el comando at + SL. Tengo esto:
at+SL=?
0:2,3
1:0,0
2:0,0
3:0,0
Si alguien aquí como ha trabajado en este módulo, guíeme.
EDIT1:
He escrito un código en ATmega16 que abre el socket, escribe en él y recibe o lee el socket.
Estoy enviando una solicitud de obtención de http a un servidor pero no puedo recibir la respuesta. ¿Cual puede ser el problema?
Aquí está mi código:
/*
* ATmega16_HLK_m30.c
*
* Created: 03-03-2015 16:12:22
* Author: B2
*/
#ifndef F_CPU
#define F_CPU 16000000UL // or whatever may be your frequency
#endif
#include <avr/io.h>
#include <util/delay.h>
#include <string.h>
#include <avr/eeprom.h>
#include "usart.h"
#include "dbg_putchar.h"
char buffer[255];
const char AT[]="at";
const char AT_WC[] = "at+WC="; //Calculation PMK
const char AT_DHCP[] = "at+dhcp="; //Set DHCP or static IP
const char AT_UTYPE[] = "at+UType="; //Set TCP or UDP
const char AT_UIP[] = "at+UIp="; //Set remote IP address
const char AT_URPORT[] = "at+URPort="; //Set remote port
const char AT_ULPORT[] = "at+ULPort="; //Set local port
const char AT_REBOOT[] = "at+Rb="; //Reboot module
const char AT_VERSION[] = "at+ver="; //Get version
const char AT_DEFAULT[] = "at+Df="; //Back to default settings
const char AT_SO[] = "at+SO="; //Socket open
const char AT_SC[] = "at+SC="; //Socket close
const char AT_SL[] = "at+SL="; //Socket check
const char AT_SW[] = "at+SW="; //Socket write
const char AT_SR[] = "at+SR="; //Socket read
const char AT_DR[] = "at+DR="; //Domain name resolution
const char AT_GPW[] = "at+GW="; //GPIO write
const char AT_GPR[] = "at+GR="; //GPIO read
const char AT_TS[] = "at+TS="; //Transparent transmission change
const char AT_MAC[] = "at+mac=";
char HttpRequest[] = "GET / HTTP/1.1\r\nHost: www.google.com\r\n\r\n";
uint8_t hlkM30SendCmd(char *,char *); //Send Command
uint8_t hlkM30AT(); //send at and check connection
uint8_t hlkM30_Dhcp(); //Configure module with dynamic IP
uint8_t hlkM30TCPClient(); //Set TCP Client
uint8_t hlkM30LocalPort(); //Set local Port
uint8_t hlkM30RemotePort(); //Set Remote Port
uint8_t hlkM30PMK(); //Calculate PMK
uint8_t hlkM30Reboot(); //Reboot
uint8_t hlkM30OpenSocket(); //Open Socket
uint8_t hlkM30ListSocket(); //List Socket
uint8_t hlkM30WriteSocket(); //Write Socket
uint8_t hlkM30ReadSocket(); //Read Socket
uint8_t hlkM30CloseSocket(); //Close Socket
int main(void)
{
USARTInit(9600);
dbg_tx_init();
dbg_puts("HLK-M30 Test\r\n");
//hlkM30Init();
hlkM30AT();
hlkM30_Dhcp();
hlkM30TCPClient();
hlkM30LocalPort();
hlkM30RemotePort();
//hlkM30CloseSocket();
//hlkM30OpenSocket();
hlkM30ListSocket();
hlkM30WriteSocket();
hlkM30ReadSocket();
//hlkM30PMK();*/
}
uint8_t hlkM30SendCmd(char *cmd,char *val)
{
UWriteString(cmd);
UWriteString(val);
UWriteData(0x0D);
}
uint8_t hlkM30AT()
{
uint8_t len=0;
uint16_t i=0;
len=strlen(AT);
UFlushBuffer();
hlkM30SendCmd(AT,"\r");
//UWriteString(AT);
//Wait for echo
_delay_ms(300);
while(i<10*len)
{
if(UDataAvailable()<len)
{
i++;
//dbg_putchar('.');
_delay_ms(10);
continue;
}
else
{
//We got an echo
//Now check it
UReadBuffer(buffer,len); //Read serial Dat
//UWriteString(buffer);
dbg_puts(buffer);
}
}
}
uint8_t hlkM30_Dhcp()
{
uint8_t len=0;
uint16_t i=0;
len=strlen(AT_DHCP);
UFlushBuffer();
hlkM30SendCmd(AT_DHCP,"1\r");
//Wait for echo
_delay_ms(300);
while(i<10*len)
{
if(UDataAvailable()<len)
{
i++;
//dbg_putchar('.');
_delay_ms(10);
continue;
}
else
{
//We got an echo
//Now check it
UReadBuffer(buffer,len); //Read serial Dat
//UWriteString(buffer);
dbg_puts(buffer);
}
}
}
uint8_t hlkM30TCPClient()
{
uint8_t len=0;
uint16_t i=0;
len=strlen(AT_UTYPE);
UFlushBuffer();
hlkM30SendCmd(AT_UTYPE,"2\r");
//Wait for echo
_delay_ms(300);
while(i<10*len)
{
if(UDataAvailable()<len)
{
i++;
//dbg_putchar('.');
_delay_ms(10);
continue;
}
else
{
//We got an echo
//Now check it
UReadBuffer(buffer,10); //Read serial Dat
//UWriteString(buffer);
dbg_puts(buffer);
}
}
}
uint8_t hlkM30LocalPort()
{
uint8_t len=0;
uint16_t i=0;
len=strlen(AT_ULPORT);
UFlushBuffer();
hlkM30SendCmd(AT_ULPORT,"80\r");
//Wait for echo
_delay_ms(300);
while(i<10*len)
{
if(UDataAvailable()<len)
{
i++;
//dbg_putchar('.');
_delay_ms(10);
continue;
}
else
{
//We got an echo
//Now check it
UReadBuffer(buffer,17); //Read serial Dat
//UWriteString(buffer);
dbg_puts(buffer);
}
}
}
uint8_t hlkM30RemotePort()
{
uint8_t len=0;
uint16_t i=0;
len=strlen(AT_URPORT);
UFlushBuffer();
hlkM30SendCmd(AT_URPORT,"80\r");
//Wait for echo
_delay_ms(300);
while(i<10*len)
{
if(UDataAvailable()<len)
{
i++;
//dbg_putchar('.');
_delay_ms(10);
continue;
}
else
{
//We got an echo
//Now check it
UReadBuffer(buffer,19); //Read serial Dat
//UWriteString(buffer);
dbg_puts(buffer);
}
}
}
uint8_t hlkM30PMK()
{
uint8_t len=0;
uint16_t i=0;
len=strlen(AT_WC);
UFlushBuffer();
hlkM30SendCmd(AT_WC,"1\r");
//Wait for echo
_delay_ms(300);
while(i<10*len)
{
if(UDataAvailable()<len)
{
i++;
//dbg_putchar('.');
_delay_ms(10);
continue;
}
else
{
//We got an echo
//Now check it
UReadBuffer(buffer,7); //Read serial Dat
//UWriteString(buffer);
dbg_puts(buffer);
}
}
}
uint8_t hlkM30OpenSocket()
{
uint8_t len=0;
uint16_t i=0;
len=strlen(AT_SO);
UFlushBuffer();
hlkM30SendCmd(AT_SO,"2,www.stealmylogin.com,80,80\r");
//Wait for echo
_delay_ms(300);
while(i<10*len)
{
if(UDataAvailable()<len)
{
i++;
//dbg_putchar('.');
_delay_ms(10);
continue;
}
else
{
//We got an echo
//Now check it
UReadBuffer(buffer,25); //Read serial Dat
//UWriteString(buffer);
dbg_puts(buffer);
}
}
}
uint8_t hlkM30ListSocket()
{
uint8_t len=0;
uint16_t i=0;
len=strlen(AT_SL);
UFlushBuffer();
hlkM30SendCmd(AT_SL,"?\r");
//Wait for echo
_delay_ms(300);
while(i<10*len)
{
if(UDataAvailable()<len)
{
i++;
//dbg_putchar('.');
_delay_ms(10);
continue;
}
else
{
//We got an echo
//Now check it
UReadBuffer(buffer,20); //Read serial Dat
//UWriteString(buffer);
dbg_puts(buffer);
}
}
}
uint8_t hlkM30CloseSocket() //Close Socket
{
uint8_t len=0;
uint16_t i=0;
len=strlen(AT_SC);
UFlushBuffer();
hlkM30SendCmd(AT_SC,"0\r");
//Wait for echo
_delay_ms(300);
while(i<10*len)
{
if(UDataAvailable()<len)
{
i++;
//dbg_putchar('.');
_delay_ms(10);
continue;
}
else
{
//We got an echo
//Now check it
UReadBuffer(buffer,7); //Read serial Dat
//UWriteString(buffer);
dbg_puts(buffer);
}
}
}
uint8_t hlkM30WriteSocket()
{
uint8_t len=0;
uint16_t i=0;
len=strlen(AT_SW);
//char str[];
UFlushBuffer();
hlkM30SendCmd(AT_SW,"0,,\"GET / HTTP/1.1\r\nHost: www.stealmylogin.com\r\n\r\n\"\r");
//hlkM30SendCmd(AT_SW,"0,,\"GET / HTTP/1.1\n\r\"\r");
//Wait for echo
_delay_ms(300);
while(i<1000)
{
if(UDataAvailable()<len)
{
i++;
//dbg_putchar('.');
_delay_ms(10);
continue;
}
else
{
//We got an echo
//Now check it
UReadBuffer(buffer,50); //Read serial Data
dbg_puts(buffer);
}
}
}
uint8_t hlkM30ReadSocket() //Read Socket
{
uint8_t len=0;
uint16_t i=0;
len=strlen(AT_SR);
//char str[];
UFlushBuffer();
hlkM30SendCmd(AT_SR,"0,50\r");
//hlkM30SendCmd(AT_SW,"0,,\"GET / HTTP/1.1\n\r\"\r");
//Wait for echo
_delay_ms(300);
while(i<10*len)
{
if(UDataAvailable()<len)
{
i++;
//dbg_putchar('.');
_delay_ms(10);
continue;
}
else
{
//We got an echo
//Now check it
UReadBuffer(buffer,50); //Read serial Dat
//UWriteString(buffer);
dbg_puts(buffer);
}
}
}
aquí está el registro que recibí:
HLK-M30 Test
at
at+dhcp=1
ok
at+UType=2
ok
at+ULPort=80
at+URPort=80
ok
at+SL=?
0:2,3
1:0,0
2:0,0
3:0,0
at+SW=0,,"GET / HTTP/1.1
ok
almylogin.com
ok
at+SR=0,50
0:ok
No entiendo qué hacer en el siguiente paso?
¿Cómo puedo enviar recibir desde el servidor?