• AVR Freaks

Hot![CLOSED] Connecting with WINC1500

Author
scotty2541
Starting Member
  • Total Posts : 39
  • Reward points : 0
  • Joined: 2003/11/07 12:41:09
  • Status: offline
2020/01/08 08:58:51 (permalink)
0

[CLOSED] Connecting with WINC1500

Hello,
I have been using a different MCU to drive the WINC1500.  I ported the ASF source code, over and it's successfully doing a few things.
But it is not connecting to my network.
Note that I am getting the callbacks telling me about the SSIDs that were found.  And the callback does tell me about multiple networks.
(There is an error in their sample:  pstrScanResult->u8AuthType was formatted at %s.  But it's just a number)
 
The details of the device are:
Firmware ver : 19.5.2 Svnrev 14274
Firmware Build Jan 26 2017 Time 22:13:34
Firmware Min driver ver : 19.3.0
Driver ver: 19.6.1
Driver built at Jan 7 2020 14:45:22
After listing all the SSIDs (and I can see in the list my desired network) then my code issues a m2m_wifi_connect_psk(...)
 
However, I NEVER get a M2M_WIFI_RESP_CON_STATE_CHANGED message.  In fact, I am displaying the message numbers, and I get a M2M_WIFI_RESP_SCAN_DONE (17), followed by the necessary M2M_WIFI_RESP_SCAN_RESULT 's (19's) and that's all.
 
Debugging and stepping into the code, it is successful in sending the comment to the device telling it to connect.
 
Here is the basic structure of the program.  First MAIN, then the WiFi callback segment.
 
int main(void) {
    unsigned char mac[6];
    uint8 valid;
    int result;
    tstrWifiInitParam initParams;
   /* MCU Specific CODE REMOVED as irrelevant to this post */
    UARTprintf("-------------\n");
    gconnected = 0;
    nm_bsp_init();
    initParams.pfAppMonCb = NULL; // InterruptCallback;
    initParams.pfAppWifiCb = WiFiCallback;
    result = m2m_wifi_init(&initParams);
 
    if (result) {
     if (result == M2M_ERR_FW_VER_MISMATCH) {
      UARTprintf("Old firmware detected\n");
     }
    }
    mac[0] = mac[1] = mac[2] = mac[3] = mac[4] = mac[5] = 0;
    m2m_wifi_get_otp_mac_address(mac, &valid);
    if (valid) {
     UARTprintf("OTP MAC %02x:%02x:%02x:%0x2:%02x:%02x \n",
       mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
    } else {
     UARTprintf("MAC is not valid\n");
    }
    m2m_wifi_get_mac_address(mac);
 UARTprintf("RAM MAC %02x:%02x:%02x:%0x2:%02x:%02x \n",
   mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);

    m2m_wifi_request_scan(M2M_WIFI_CH_ALL);

    while(1) {
     m2m_wifi_handle_events(NULL);
     if (gscancomplete == 0) continue;

     if (gconnected == NOT_CONNECTED) {

         m2m_wifi_enable_dhcp(0);
      tstrNetworkId net;
      tstrAuthPsk pwd;
      net.enuChannel = M2M_WIFI_CH_ALL;
      net.pu8Bssid = NULL;
      net.pu8Ssid = SSID;
      net.u8SsidLen = sizeof(SSID);

      pwd.pu8Psk = NULL;
      pwd.pu8Passphrase = SSIDPWD;
      pwd.u8PassphraseLen = sizeof(SSIDPWD);

         m2m_wifi_connect_psk(WIFI_CRED_DONTSAVE,&net,&pwd);

         gconnected = PENDING_CONNECT;

     }
    }
}

Then the WiFi Callback:

void WiFiCallback(uint8_t u8MsgType, void *pvMsg) {
 UARTprintf("Wifi\n");
 static uint8 u8ScanResultIdx = 0;
 UARTprintf(" --- MSG %d \r\n", u8MsgType);

 switch(u8MsgType) {

 case M2M_WIFI_RESP_SCAN_DONE : {
     tstrM2mScanDone *pstrInfo = (tstrM2mScanDone*)pvMsg;

     UARTprintf("Num of AP found %d\n",pstrInfo->u8NumofCh);
     if(pstrInfo->s8ScanState == M2M_SUCCESS) {
      u8ScanResultIdx = 0;
      if(pstrInfo->u8NumofCh >= 1) {
       m2m_wifi_req_scan_result(u8ScanResultIdx);
       u8ScanResultIdx ++;
      } else {
       UARTprintf("No AP Found Rescan\n");
       m2m_wifi_request_scan(M2M_WIFI_CH_ALL);
      }
     } else {
      UARTprintf("(ERR) Scan fail with error <%d>\n",pstrInfo->s8ScanState);
     }
     break;
    }
 case M2M_WIFI_RESP_SCAN_RESULT : {
  tstrM2mWifiscanResult *pstrScanResult =(tstrM2mWifiscanResult*)pvMsg;
  uint8 u8NumFoundAPs = m2m_wifi_get_num_ap_found();

  UARTprintf(">>%02d RI %d SEC %d CH %02d BSSID %02X:%02X:%02X:%02X:%02X:%02X SSID %s\n",
   pstrScanResult->u8index,
   pstrScanResult->s8rssi,
   pstrScanResult->u8AuthType,
   pstrScanResult->u8ch,
   pstrScanResult->au8BSSID[0], pstrScanResult->au8BSSID[1], pstrScanResult->au8BSSID[2],
   pstrScanResult->au8BSSID[3], pstrScanResult->au8BSSID[4], pstrScanResult->au8BSSID[5],
   pstrScanResult->au8SSID);

  if(u8ScanResultIdx < u8NumFoundAPs) {
   // Read the next scan result
   m2m_wifi_req_scan_result(u8ScanResultIdx);
   u8ScanResultIdx ++;
  } else {
   gscancomplete = 1;
  }
 }
 break;

 case M2M_WIFI_RESP_CON_STATE_CHANGED : {
  tstrM2mWifiStateChanged *pstrWifiState = (tstrM2mWifiStateChanged *)pvMsg;
  if (pstrWifiState->u8CurrState == M2M_WIFI_CONNECTED) {
   UARTprintf("Wi-Fi connected\r\n");
   tstrM2MIPConfig ip_client;
   ip_client.u32StaticIP = _htonl(0xc0a801f0); // Provide the required Static IP
   ip_client.u32DNS = _htonl(0xc0a80101); // Provide DNS server details
   ip_client.u32SubnetMask = _htonl(0xFFFFFF00); // Provide the SubnetMask for the currently connected AP
   ip_client.u32Gateway = _htonl(0xc0a80101); // Provide the GAteway IP for the AP
   UARTprintf("Wi-Fi setting static ip\r\n");
   m2m_wifi_set_static_ip(&ip_client);
   gconnected = CONNECTED;
  } else {
   UARTprintf("Wi-Fi NOT connected\r\n");
  }
 }
 
/*   Other statements.....  */

The detected network I want to connect to is:
>>00 RI -45 EC 2 CH 09 BSSID f8:18:97:c8:a4:f1 SSID MyNET
Are there other steps which need to be taken prior to telling it to connect?
 
Any advice would be appreciated.
 
post edited by scotty2541 - 2020/01/21 12:43:17

{Code shown is not to scale}
-Scotty
#1

7 Replies Related Threads

    aschen0866
    Super Member
    • Total Posts : 4534
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    Re: Connecting with WINC1500 2020/01/08 12:25:48 (permalink)
    5 (1)
    I am pretty sure both SSID and password need to use strlen() not sizeof(). I would use m2m_wifi_connect() and pass in the proper security type.
    #2
    scotty2541
    Starting Member
    • Total Posts : 39
    • Reward points : 0
    • Joined: 2003/11/07 12:41:09
    • Status: offline
    Re: Connecting with WINC1500 2020/01/08 13:00:29 (permalink)
    0
    Nope, not the solution.  I also tried that when I saw it.
    But thanks for the try.
     
    Code for the SSID actually takes the value up to the first null, and counts those characters (that's down in the "hif()" stuff).
    But it does use the byte count for the password.
     
    I updated these to 
          net.enuChannel = M2M_WIFI_CH_ALL;
          net.pu8Bssid = NULL;
          net.pu8Ssid = SSID;
          net.u8SsidLen = (uint8) sizeof(SSID) - 1;

          pwd.pu8Psk = NULL;
          pwd.pu8Passphrase = SSIDPWD;
          pwd.u8PassphraseLen = (uint8) sizeof(SSIDPWD) - 1;

    but it had no affect...  Which is there is no effect occurring.
     
    I debugged and traced the messages all the way into the "hif" code, and I could actually post a reply here that has the block that is being send to the device.  But I don't know that it would help anyone.
     
    The fact that it can enumerate all the WiFi SSIDs it finds, but doesn't react to the command to connect to one of them is rather suspicions... and annoying.
     

    {Code shown is not to scale}
    -Scotty
    #3
    scotty2541
    Starting Member
    • Total Posts : 39
    • Reward points : 0
    • Joined: 2003/11/07 12:41:09
    • Status: offline
    Re: Connecting with WINC1500 2020/01/08 13:10:10 (permalink)
    0
    <trying to delete a post...  I guess I can only edit it, and remove almost all the content>
    post edited by scotty2541 - 2020/01/08 13:15:39

    {Code shown is not to scale}
    -Scotty
    #4
    aschen0866
    Super Member
    • Total Posts : 4534
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    Re: Connecting with WINC1500 2020/01/08 18:43:25 (permalink)
    0
    What channel does your WiFi router use? If it is 1, can you try a different channel? Just to make sure you don't have a defective WINC1500 module.
    #5
    scotty2541
    Starting Member
    • Total Posts : 39
    • Reward points : 0
    • Joined: 2003/11/07 12:41:09
    • Status: offline
    Re: Connecting with WINC1500 2020/01/08 20:10:14 (permalink)
    0
    As my post shows (but it was toward the bottom), the SSID of the network indicated channel 9.
    I had set the device for "ALL_CHANNELS", so I changed it and retested:

    while(1) {
    m2m_wifi_handle_events(NULL);
    if (gscancomplete == 0) continue;
     
    if (gconnected == NOT_CONNECTED) {
        net.enuChannel = M2M_WIFI_CH_9;
        net.pu8Bssid = NULL;
        net.pu8Ssid = SSID;
        net.u8SsidLen = (uint8) sizeof(SSID) - 1;
        pwd.pu8Psk = NULL;
        pwd.pu8Passphrase = SSIDPWD;
        pwd.u8PassphraseLen = (uint8) sizeof(SSIDPWD) - 1;
        m2m_wifi_connect_psk(WIFI_CRED_DONTSAVE,&net,&pwd);
        gconnected = PENDING_CONNECT;
     
     
    }

    But still no luck. It's been sitting for several minutes with no event triggered.
    post edited by scotty2541 - 2020/01/08 20:13:56

    {Code shown is not to scale}
    -Scotty
    #6
    scotty2541
    Starting Member
    • Total Posts : 39
    • Reward points : 0
    • Joined: 2003/11/07 12:41:09
    • Status: offline
    Re: Connecting with WINC1500 2020/01/21 12:45:35 (permalink)
    0
    As it turns out...  the MLA library does NOT work with this unit "out of the box".
    In fact, the firmward of the device is 19.5, and the driver source is 19.6.
     
    I was provided with the earlier firmware and it works.
     
    Why it is complete dead because of one small "sub" version number is beyond me.

    {Code shown is not to scale}
    -Scotty
    #7
    aschen0866
    Super Member
    • Total Posts : 4534
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    Re: Connecting with WINC1500 2020/01/21 15:51:26 (permalink)
    0
    scotty2541
    As it turns out...  the MLA library does NOT work with this unit "out of the box".
    In fact, the firmward of the device is 19.5, and the driver source is 19.6.
     
    I was provided with the earlier firmware and it works.
     
    Why it is complete dead because of one small "sub" version number is beyond me.


    The host driver version must be equal or less than the WINC module's firmware version or you'll get error code M2M_ERR_FW_VER_MISMATCH (-13) when you call m2m_wifi_init().
    #8
    Jump to:
    © 2020 APG vNext Commercial Version 4.5