コード例 #1
0
void
tcpClient_main(intptr_t exinf) {

	EthernetInterface network;
	TCPSocketConnection socket;

	/* syslogの設定 */
    SVC_PERROR(syslog_msk_log(LOG_UPTO(LOG_INFO), LOG_UPTO(LOG_EMERG)));

	syslog(LOG_NOTICE, "tcpClient:");
    syslog(LOG_NOTICE, "Sample program starts (exinf = %d).", (int_t) exinf);
    syslog(LOG_NOTICE, "LOG_NOTICE: Network Setting up...");

#if (USE_DHCP == 1)
    if (network.init() != 0) {                             //for DHCP Server
#else
    if (network.init(IP_ADDRESS, SUBNET_MASK, DEFAULT_GATEWAY) != 0) { //for Static IP Address (IPAddress, NetMasks, Gateway)
#endif
		syslog(LOG_NOTICE, "Network Initialize Error");
        return;
    }
    syslog(LOG_NOTICE, "Network was initialized successfully");
    while (network.connect(5000) != 0) {
        syslog(LOG_NOTICE, "LOG_NOTICE: Network Connect Error");
    }

    syslog(LOG_NOTICE, "MAC Address is %s", network.getMACAddress());
    syslog(LOG_NOTICE, "IP Address is %s", network.getIPAddress());
    syslog(LOG_NOTICE, "NetMask is %s", network.getNetworkMask());
    syslog(LOG_NOTICE, "Gateway Address is %s", network.getGateway());
    syslog(LOG_NOTICE, "Network Setup OK...");
	
    while (socket.connect(SERVER, HTTP_PORT) < 0) {
        syslog(LOG_EMERG, "Unable to connect to (%s) on port (%d)", SERVER, HTTP_PORT);
        wait(1.0);
    }
    ClientGreet(&socket);
    socket.close();
    syslog(LOG_NOTICE, "program end");
}

// set mac address
void mbed_mac_address(char *mac) {
	// PEACH1
    mac[0] = 0x00;
    mac[1] = 0x02;
    mac[2] = 0xF7;
    mac[3] = 0xF0;
    mac[4] = 0x00;
    mac[5] = 0x00;
}
コード例 #2
0
HTTPAPI_RESULT HTTPAPI_Init(void)
{
    LogInfo("HTTPAPI_Init::Start\r\n");
    time_t ctTime;
    ctTime = time(NULL);
    HTTPAPI_RESULT result;
    LogInfo("HTTAPI_Init::Time is now (UTC) %s\r\n", ctime(&ctTime));
    if (eth.init())
    {
        LogInfo("HTTPAPI_Init::Error with initing the Ethernet Interface\r\n");
        result = HTTPAPI_INIT_FAILED;
    }
    else
    {
        LogInfo("HTTPAPI_Init::Ethernet interface was inited!\r\n");
        if (eth.connect(30000))
        {
            LogError("HTTPAPI_Init::Error with connecting.\r\n");
            result = HTTPAPI_INIT_FAILED;
        }
        else
        {
            LogInfo("HTTAPI_Init::Ethernet interface was connected (brought up)!\r\n");
            LogInfo("HTTAPI_Init::MAC address %s\r\n", eth.getMACAddress());
            LogInfo("HTTAPI_Init::IP address %s\r\n", eth.getIPAddress());
            if (ntp.setTime("0.pool.ntp.org") == 0)
            {
                LogInfo("HTTAPI_Init:: Successfully set time\r\n");
                LogInfo("HTTAPI_Init::Time is now (UTC) %s\r\n", ctime(&ctTime));
                result = HTTPAPI_OK;
            }
            else
            {
                LogError("HTTPAPI_INIT::Unable to set time.  Init failed");
                result = HTTPAPI_INIT_FAILED;
            }
        }
    }
    LogInfo("HTTPAPI_Init::End\r\n");
    return result;
}
コード例 #3
0
ファイル: app.cpp プロジェクト: sg-/sdw-workshop
void app_start(int /*argc*/, char* /*argv*/[]) {

    //Sets the console baud-rate
    output.baud(115200);

    // start the accelerometer
    acc.enable();

    // print device name for easy reference
    output.printf("Device Name is '%s'\r\n\r\n",MBED_ENDPOINT_NAME);

    // This sets up the network interface configuration which will be used
    // by LWM2M Client API to communicate with mbed Device server.
    eth.init(); //Use DHCP
    eth.connect();
    output.printf("%s\n", eth.getMACAddress());
    char *ip = eth.getIPAddress();
    if (ip) {
        output.printf("IP Address is: %s\n", ip);
    } else {
        error("Failed to aquire IP address\n");
    }

    lwipv4_socket_init();

    // On press of SW3 button on K64F board, example application
    // will call unregister API towards mbed Device Server
    // unreg_button.fall(&mbed_client,&MbedClient::test_unregister);

    // Create LWM2M Client API interface to manage register and unregister
    mbed_client.create_interface();

    // Create LWM2M server object specifying mbed device server
    // information.
    M2MSecurity* register_object = mbed_client.create_register_object();

    // Create LWM2M device object specifying device resources
    // as per OMA LWM2M specification.
    M2MDevice* device_object = mbed_client.create_device_object();

    // Create Generic object specifying custom resources
    M2MObject* sdw_object = mbed_client.create_sdw_object();
    
    // Create Generic object specifying custom resources
    M2MObject* led_object = mbed_client.create_led_object();

    // Add all the objects that you would like to register
    // into the list and pass the list for register API.
    M2MObjectList object_list;
    object_list.push_back(device_object);
    object_list.push_back(sdw_object);
    object_list.push_back(led_object);

    mbed_client.set_register_object(register_object);

    // Issue register command.
    FunctionPointer2<void, M2MSecurity*, M2MObjectList> fp(&mbed_client, &MbedClient::test_register);
    minar::Scheduler::postCallback(fp.bind(register_object, object_list));
    minar::Scheduler::postCallback(&mbed_client, &MbedClient::update_sdw_resource).period(minar::milliseconds(1000));
    minar::Scheduler::postCallback(&mbed_client, &MbedClient::test_update_register).period(minar::milliseconds(25000));
}