IOT - Bosch
  • Introduction
  • Devices
    • Bosch XDK 110
      • Introduction
      • Operating System
      • Hardware
        • Sensors
          • Accelerometer
            • C
          • Gyroscope
            • C
            • Mita
          • Magnetometer
            • C
          • Environmental
            • C
            • Mita
          • Ambient Light
            • C
            • Mita
          • Acoustic
            • C
      • Software
        • XDK WorkSpace
          • Structure
          • Debug
          • Supported languages
            • C
              • Static Library (.a)
            • XDK Live - Mita
            • MicroFlo
      • Connectivity
        • Bluetooth Low Energy (BLE)
          • Overview
          • General Info
          • Implementation
            • C
            • XDK Live
        • WI-FI
          • OverView
          • Implementation
            • C
            • XDK Live
        • WI-FI Enterprise
      • Protocols
        • CoAP
          • Overview
          • Implementation -TBD
        • HTTP
          • Overview
          • Structure and Methods
          • Implementation
            • C - Rest
            • C - Post
            • XDK Live
        • HTTPS
          • Overview
          • Implementation TBD
        • LWM2M
          • Overview
          • Implementation TBD
        • MQTT
          • Overview
          • Implementation
            • C
            • XDK Live
        • USB
          • Overview
          • Implementation TBD
      • Data Storage
      • XDK Extension Bus
      • Community
      • Applications
        • Language C
          • HomeAssitant - MQTT
            • Prerequisites
            • Server
            • Device
          • IOTA-MQTT-XDK
            • Prerequisites
            • XDK110
            • Mqtt JSON to MAM
            • SensorHub
            • Demo
        • Language XDK Live
          • MQTT
            • Hello World
            • HomeAssistant
              • Prerequisites
              • Server
              • Device
            • Docker-HomeAssistant
          • HTTP
            • Roku Remote Control
              • Roku API
              • MITA
                • Example
    • Bosch AMRA
    • Bosch GLM 100C
    • Bosch FLEXIDOME IP panoramic
    • Bosch GLM 100C
    • Bosch Rexroth Nexo
    • Bosch Rexroth PRC 7000
    • Bosch RRC / CT100
    • Bosch Rexroth IoT Gateway
  • Bosch IOT Solutions
    • Bosch IOT Projects
      • Smart Home
      • Industry 4.0
      • Smart Cities
      • Connected-mobility
    • Bosch IOT Suite
      • Bosch Analytics
      • Bosch IOT Hub
      • Bosch Iot Permission
      • IoT Remote Manager
      • IoT Rollouts
      • IoT Things
      • Demo TBD **
    • BPM and BRM
  • IOTA
    • Introduction
      • Tangle
      • Glossary
      • Differences with other tech
      • How does iota work
      • Developers
    • Qubic
      • What is Qubic?
      • Target
      • Qubic Protocol
    • Ecosystem
    • Applications
      • Python
      • XDK110
        • Prerequisites
        • XDK110
        • Mqtt JSON to MAM
        • SensorHub
    • Bosch/IOTA
  • ByteBall
    • SmartContract
    • Use Case
      • BoshCoins
Powered by GitBook
On this page

Was this helpful?

  1. Devices
  2. Bosch XDK 110
  3. Connectivity
  4. WI-FI
  5. Implementation

C

The next code is based on language C. This code would help us to connect and get the ip retrieved.

First we need to import the libraries of wifi module.

/* system header files */
#include "stdio.h"
/* additional interface header files */
#include "FreeRTOS.h"
#include "timers.h"

#include "BCDS_NetworkConfig.h"
#include "BCDS_WlanConnect.h"

#include "BCDS_CmdProcessor.h"
#include "BCDS_Assert.h"

We need to set up the SSID and the password with your respective credentials.

/* macros ******************************************************************* */

#warning Set these Macros accordingly, before running this application
#define USE_DHCP    1    // 1: DHCP; 0: Static IP
#define USE_WPA        1    // 1: WPA; 0: Open Access point
#define SSID        "yourWifiNetworkSSID"
#define PW            "yourWifiNetworkPW"

/* local functions ********************************************************** */

We define a function to initialized the wifi, and use the method of WlanConnect_Init()

* If the Wi-Fi is initialized, it is possible to scan for surrounding Wi-Fi networks before connecting to them. In order to do that, three variable types are of particular interest.

Retcode_T - Return state for programable request logics

WlanConnect_ScanInterval_T - Defined time period in which intervals the scan occurs

WlanConnect_ScanList_T - A struct which contains the scanned network informations.

/* local functions ********************************************************** */
static void initWifi(void)
{
  /* initialize the Wi-Fi module */
  WlanConnect_Init();
}

The function NetworkConfig_Ipv4Value() converts the committed decimal IP parameters to hexadecimal IP parameters.

The NetworkConfig_SetIpStatic() function sets the committed IP parameters in the interface.

static void setIPSettings(void) {
#if USE_DHCP
    NetworkConfig_SetIpDhcp(NULL);
#else
    NetworkConfig_IpSettings_T myIpSet;
    myIpSet.isDHCP = (uint8_t) NETWORKCONFIG_DHCP_DISABLED;
    myIpSet.ipV4 = NetworkConfig_Ipv4Value(192, 168, 0, 2);
    myIpSet.ipV4DnsServer = NetworkConfig_Ipv4Value(192, 168, 0, 1);
    myIpSet.ipV4Gateway = NetworkConfig_Ipv4Value(192, 168, 0, 1);
    myIpSet.ipV4Mask = NetworkConfig_Ipv4Value(255, 255, 255, 0);
    NetworkConfig_SetIpStatic(myIpSet);
#endif
}
static void connectWiFi(void){
    WlanConnect_SSID_T connectSSID = (WlanConnect_SSID_T) SSID;
#if USE_WPA
    WlanConnect_PassPhrase_T connectPassPhrase = (WlanConnect_PassPhrase_T) PW;
    WlanConnect_WPA(connectSSID, connectPassPhrase, NULL);
#else
    WlanConnect_Open(connectSSID, NULL);
#endif // USE_WPA
}

static void printIP(void){
    NetworkConfig_IpSettings_T myIp;
    NetworkConfig_GetIpSettings(&myIp);

    // insert a delay here, if the IP is not properly printed
    printf("The IP was retrieved: %u.%u.%u.%u \n\r",
    (unsigned int) (NetworkConfig_Ipv4Byte(myIp.ipV4, 3)),
    (unsigned int) (NetworkConfig_Ipv4Byte(myIp.ipV4, 2)),
    (unsigned int) (NetworkConfig_Ipv4Byte(myIp.ipV4, 1)),
    (unsigned int) (NetworkConfig_Ipv4Byte(myIp.ipV4, 0)));
}

/* global functions ********************************************************* */

/**
 * @brief This is a template function where the user can write his custom application.
 *
 */
CmdProcessor_T *appCmdProcessor;

void appInitSystem(void *CmdProcessorHandle, uint32_t param2) {
    if(CmdProcessorHandle == NULL){
        printf("Command processor handle is null \n\r");
        assert(false);
    }
    BCDS_UNUSED(param2);
    appCmdProcessor = CmdProcessorHandle;

    initWifi();
    setIPSettings();
    connectWiFi();
    printIP();
}
PreviousImplementationNextXDK Live

Last updated 5 years ago

Was this helpful?