Hi AGAIN!, i just make this run in STM32, with an adhoc open network, but when y wanna make it connect to a WPA2-PSK network, with the parameters the library helps says, it did not work, even if I copy the explame as it is in the library, the compilers marks an error
Code: Select all
//Net_Wireless_MCW1001_SetSecurity_WPA(_NET_WIRELESS_MCW1001_CP_1, _NET_WIRELESS_MCW1001_WPA_TYPE_2, &key);
and when i write :
Code: Select all
//Net_Wireless_MCW1001_SetSecurity_WPA(_NET_WIRELESS_MCW1001_CP_1, _NET_WIRELESS_MCW1001_WPA_PSK2, &key);
it "works", but not connect to the AP
Other thing is that, when i wanna send something in TCP this doesn't works:
Code: Select all
response = Net_Wireless_MCW1001_TCP_SendBytes(socketHandleGlobal, &buffer, 1, &numOfSendBytes);
but
Code: Select all
char buffer []= "STRING" ;
response = Net_Wireless_MCW1001_TCP_SendString(socketHandleGlobal, buffer , &numOfSendBytes);
, here is the complete solution (Workin in OPEN adhoc, but i wanna make it work in WPA2-PSK network)
Code: Select all
/*
* Project name:
WiFi_Demo.vtft
* Generated by:
Visual TFT
* Date of creation
4/21/2012
* Time of creation
11:54:30 AM
* Test configuration:
MCU: STM32F407VG
Dev.Board: mikromedia for STM32 M4
Oscillator: HSI-PLL, 140.000MHz
ext. modules:
ick on mikrobus2
SW: mikroC PRO for ARM
*/
////////////////////////////////////////////////////////////////////////////////
sbit Net_Wireless_MCW1001_Chip_RST at GPIOA_ODR.B8;
sbit STAT at ODR13_GPIOC_ODR_bit;
sbit DATA at ODR12_GPIOC_ODR_bit;
sbit PB at IDR1_GPIOA_IDR_bit;
sbit CG at IDR2_GPIOA_IDR_bit;
sbit PP at IDR3_GPIOA_IDR_bit;
sbit PA at IDR0_GPIOC_IDR_bit;
sbit BUENOS at ODR6_GPIOB_ODR_bit;
sbit MALOS at ODR5_GPIOA_ODR_bit;
sbit CONTADOR at ODR0_GPIOB_ODR_bit;
sbit PPS at ODR8_GPIOB_ODR_bit;
sbit RUN at ODR5_GPIOC_ODR_bit;
////////////////////////////////////////////////////////////////////////////////
// Global variables
char socketHandleGlobal;
char strSSID[13] = "DRACOTRY";
//char key[11]="260D5243A5";
unsigned int remotePort = 256;
char commandOldValue;
char channels[11] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
char myMac[6] = {0x22, 0x33, 0x44, 0x55, 0x44, 0x22 };
char gatewayAdd[4] = {169, 254, 24, 200};
char response;
unsigned int seguro = 0;
//void RefreshAndDrawNetStatus();
//void CheckTcpReceive();
////////////////////////////////////////////////////////////////////////////////
// Timer interrupt
unsigned int wifiTmr = 0, netStatusTmr = 0;
void TIMER2_interrupt() iv IVT_INT_TIM2{
TIM2_SR.UIF = 0;
wifiTmr++;
netStatusTmr++;
if(wifiTmr >= 5) {
Net_Wireless_MCW1001_Time++ ; // increment WiFi library counter
wifiTmr = 0;
}
}
////////////////////////////////////////////////////////////////////////////////
// Initialization of MCU modules
void MCU_Init() {
// Initialization of timer..............
RCC_APB1ENR.TIM2EN = 1; // Enable clock gating for timer module 2
TIM2_CR1.CEN = 0; // Disable timer
TIM2_PSC = 213; // Set timer prescaler.
TIM2_ARR = 65420;
NVIC_IntEnable(IVT_INT_TIM2); // Enable timer interrupt
TIM2_DIER.UIE = 1; // Update interrupt enable
TIM2_CR1.CEN = 1; // Enable timer
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Initialization of WiFi module
void InitWiFi() {
Net_Wireless_MCW1001_TimeToWait = 1;
response = 1;
while(response != 0)
response = Net_Wireless_MCW1001_SetMode(_NET_WIRELESS_MCW1001_CP_1, _NET_WIRELESS_MCW1001_MODE_ADHOC); // Set "Connection Profile 1" mode (Ad-Hoc mode)
// WiFi is ready
Net_Wireless_MCW1001_TimeToWait = 10;
Net_Wireless_MCW1001_InitDHCP(); // Init DHCP to get network parameter
Net_Wireless_MCW1001_SetSSID(_NET_WIRELESS_MCW1001_CP_1, strSSID); // Set SSID of network
Net_Wireless_MCW1001_SetSecurity_Open(_NET_WIRELESS_MCW1001_CP_1); // Set open security level
//Net_Wireless_MCW1001_SetSecurity_WPA(_NET_WIRELESS_MCW1001_CP_1, _NET_WIRELESS_MCW1001_WPA_TYPE_2, &key);
Net_Wireless_MCW1001_SetChannelList(1, channels); // Choose only channerl one for communication
Net_Wireless_MCW1001_SetMAC(myMac); // Set my MAC address
Net_Wireless_MCW1001_SetArpTime(1); // Set gratuitous ARP timing
Net_Wireless_MCW1001_SetRetryCount(5, 255); // Retrying the network connection forever.
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Constants that define the protocol.
// For example, when server receive TCP packet with "SWITCH_E8_ON" command, server know that switch PJ0 on MMB is pressed,
// and then server turn PJ0 LED on. When button PD0 is pressed server send TCP packet with "LED_PD0_ON" command to MMB, and client turn on
// PD0 LED on display.
const char SWITCH_E8_ON = 1;
const char SWITCH_E8_OFF = 2;
//
const char SWITCH_E9_ON = 3;
const char SWITCH_E9_OFF = 4;
//
const char SWITCH_E10_ON = 5;
const char SWITCH_E10_OFF = 6;
//
const char SWITCH_E11_ON = 7;
const char SWITCH_E11_OFF = 8;
const char LED_PD0_ON = 9;
const char LED_PD0_OFF = 10;
//
const char LED_PD1_ON = 11 ;
const char LED_PD1_OFF = 12;
//
const char LED_PD2_ON = 13;
const char LED_PD2_OFF = 14;
//
const char LED_PD3_ON = 15;
const char LED_PD3_OFF = 16;
//////////////////////
////////////////////////////////////////////////////////////////////////////////
// This function check network and TCP status
void RefreshAndDrawNetStatus() {
char i, tmpIP[16], response, markFound, markStatus, numOfScanRes, connStatus;
char connectCnt, connectResponse;
unsigned int time;
// Try to ping gateway.
response = Net_Wireless_MCW1001_PingSend(gatewayAdd, &time);
if(response != 0) {
Net_Wireless_MCW1001_Disconnect();
//Delay_ms(500);
}
markStatus = 1;
while(markStatus != 2) {
// Get network status
Net_Wireless_MCW1001_GetNetworkStatus();
if(Net_Wireless_MCW1001_Properties.networkStatus != _NET_WIRELESS_MCW1001_STATUS_CONN_DHCP) { // If this true, our module is disconnected from network
// Refresh connection indicators
commandOldValue = 255;
markStatus = 0;
// Try to connect
while(1) {
// Search SSID "WiFi Control"
markFound = 0;
while(markFound != 1) {
while(1) {
response = Net_Wireless_MCW1001_ScanStart(255, &numOfScanRes); // Scan network
if(response == 0) // Check if scanning successful
break;
//Delay_ms(500);
}
// Check whether is there our ("WiFi Control") network
for(i = 1; i <= numOfScanRes; i++) {
response = Net_Wireless_MCW1001_GetScanResult(i);
//strncpy(strTmp, Net_Wireless_MCW1001_ScanResult.SSID, Net_Wireless_MCW1001_ScanResult.SSIDLength);
if(Net_Wireless_MCW1001_ScanResult.SSIDLength > 13) {
//No se que pasa aqui
}
else
// strTmp[Net_Wireless_MCW1001_ScanResult.SSIDLength] = '\0';
markFound = 1;
//Delay_ms(700);
}
}
// Connect to AdHoc network
response = Net_Wireless_MCW1001_Connect(_NET_WIRELESS_MCW1001_CP_1, &connStatus);
if((response != 0)||(connStatus != 1)) {
//No se pudo conectar
BUENOS = 0;
// Delay_ms(500);
}
else {
//Si se pudo conectar
BUENOS = 1;
break;
}
}
}
// Check whether the TCP connection is established
if(Net_Wireless_MCW1001_TCP_Status(socketHandleGlobal, 0xff) != 0) {
if(markStatus == 1) {
//La red se desconecto
CONTADOR = 0;
}
// Connecting to TCP sever
// "Connecting To:");
//, "Server");
socketHandleGlobal = 0;
response = Net_Wireless_MCW1001_SocketClose(socketHandleGlobal);
response = Net_Wireless_MCW1001_SocketCreate(&socketHandleGlobal, _NET_WIRELESS_MCW1001_SOCKET_TYPE_TCP);
// Socket created successfully?
if( (response == 0)&&(socketHandleGlobal <= 253) ) {
// Try to connect to target server (try max 5 times)
for(connectCnt = 0; connectCnt < 5; connectCnt++) {
response = Net_Wireless_MCW1001_TCP_Connect(socketHandleGlobal, remotePort, gatewayAdd, &connectResponse);
if(connectResponse == 0) {
markStatus = 2;
CONTADOR = 1;
//strcpy(LabelConnStatus_Caption, "Connected");
break;
}
//Delay_ms(300);
}
}
}
else
markStatus = 2;
}
}
//////////////////////////
////Decode Command in received TCP packet
void ComandDecode(signed char command) {
if(command < 20) {
switch(command) {
case LED_PD0_ON : {
break;
}
case LED_PD0_OFF : {
break;
}
case LED_PD1_ON : {
break;
}
case LED_PD1_OFF : {
break;
}
case LED_PD2_ON : {
break;
}
case LED_PD2_OFF : {
break;
}
case LED_PD3_ON : {
break;
}
case LED_PD3_OFF : {
break;
}
}
}
}
////////////////////////////////////////////////////////////////////////////////
// Check TCP buffer to see is there some received data
void CheckTcpReceive() {
char response, dat[10], i;
unsigned int numOfReceiveBytes = 0;
response = Net_Wireless_MCW1001_TCP_ReadBytes(&socketHandleGlobal, 10, dat, &numOfReceiveBytes);
if( (response == 0) && (numOfReceiveBytes != 0) ) { // If there is no error, and number of received bytes is greater than zero
for(i = 0; i < numOfReceiveBytes; i++) {
ComandDecode(dat[i]);
}
}
}
/////////////////////////////////////////////////////////////////////////////////
void Envio_de_datos()
{
char response, txBuffer ,numOfSendBytes;
char envio[3] = "BN";
response = Net_Wireless_MCW1001_TCP_SendString(socketHandleGlobal, envio, &numOfSendBytes);
}
//////////////////////////////////////////////////////////////////////////////////
void CHECKBUTTON(){
if ((PB == 1) & (SEGURO == 0))
{
seguro = 1;
Envio_de_datos();
}
if ((PB == 0) & (SEGURO == 1))
{
seguro = 0;
}
}
void main() {
////////////////////////////////////////////////////////////////////////////////
// configure DATA and STAT pins as output
GPIO_Digital_Input(&GPIOA_BASE, _GPIO_PINMASK_1 | _GPIO_PINMASK_2 | _GPIO_PINMASK_3); // Set PA1-3 as digital input
GPIO_Digital_Input(&GPIOC_IDR, _GPIO_PINMASK_0);
GPIO_Digital_Output(&GPIOA_ODR,_GPIO_PINMASK_5| _GPIO_PINMASK_8);
GPIO_Digital_Output(&GPIOB_BASE, _GPIO_PINMASK_0 | _GPIO_PINMASK_6 | _GPIO_PINMASK_8 );
GPIO_Digital_Output(&GPIOC_BASE, _GPIO_PINMASK_5 | _GPIO_PINMASK_12 | _GPIO_PINMASK_13);
////////////////////////////////////////////////////////////////////////////////
//////////////////////////Secuencia de valores repetidos////////////////////////
GPIO_Digital_Input(&GPIOB_IDR, _GPIO_PINMASK_3); //Repetida de RST
//PB1,PC4,PA15,PC2
GPIO_Digital_Input(&GPIOB_IDR, _GPIO_PINMASK_1);
GPIO_Digital_Input(&GPIOC_IDR, _GPIO_PINMASK_4);
GPIO_Digital_Input(&GPIOA_IDR, _GPIO_PINMASK_15);
GPIO_Digital_Input(&GPIOC_IDR, _GPIO_PINMASK_2);
///////////////////////////////////////////////////////////////////////////////
STAT = 0; // turn OFF the STAT LED
DATA = 0; // turn OFF the DATA LED
BUENOS = 0; // Turn OFF all METRICS indicators
MALOS = 0;
CONTADOR = 0;
PPS =1;
SEGURO = 0;
////////////////////////////////////////////////////////////////////////////////
MCU_Init();
Net_Wireless_MCW1001_HwReset();
UART3_Init_Advanced(115200, _UART_8_BIT_DATA, _UART_NOPARITY, _UART_TWO_STOPBITS, &_GPIO_MODULE_USART3_PC10_11);
InitWiFi();
MALOS = 1;
RefreshAndDrawNetStatus();
while(1) {
CheckTcpReceive();
CHECKBUTTON();
//Envio_de_datos();
if(netStatusTmr >= 10) { // Approximately every 2 second check network status
RefreshAndDrawNetStatus();
netStatusTmr = 0;
}
}
}
ANY HELP??