Ejemplo n.º 1
0
int main(void)
{
	(void)printf("Initializing mbed specific things...\r\n");

	mbed_log_init();
	mbedtime_init();

	if (EthernetInterface::init())
	{
		(void)printf("Error initializing EthernetInterface.\r\n");
		return -1;
	}

	if (setupRealTime() != 0)
	{
		(void)printf("Failed setting up real time clock\r\n");
		return -1;
	}

	if (EthernetInterface::connect())
	{
		(void)printf("Error connecting EthernetInterface.\r\n");
		return -1;
	}

	iothub_client_sample_amqp_run();

	(void)EthernetInterface::disconnect();
}
Ejemplo n.º 2
0
int main(void)
{
    (void)printf("Initializing mbed specific things...\r\n");

    /* These are needed in order to initialize the time provider for Proton-C */
    mbed_log_init();
    mbedtime_init();

	if (EthernetInterface::init())
	{
		(void)printf("Error initializing EthernetInterface.\r\n");
		return -1;
	}

	if (setupRealTime() != 0)
	{
		(void)printf("Failed setting up real time clock\r\n");
		return -1;
	}

	if (EthernetInterface::connect())
	{
		(void)printf("Error connecting EthernetInterface.\r\n");
		return -1;
	}

    remote_monitoring_run();

	(void)EthernetInterface::disconnect();

    return 0;
}
Ejemplo n.º 3
0
int main(void)
{
    (void)printf("Initializing mbed specific things...\r\n");

    if (EthernetInterface::init())
    {
        (void)printf("Error initializing EthernetInterface.\r\n");
        return -1;
    }

    if (setupRealTime() != 0)
    {
        (void)printf("Failed setting up real time clock\r\n");
        return -1;
    }

    iothub_client_sample_http_run();

    return 0;
}
Ejemplo n.º 4
0
int platform_init(void)
{
    int result;

    if (EthernetInterface::init())
    {
        result = __LINE__;
    }
    else if (setupRealTime() != 0)
    {
        result = __LINE__;
    } 
    else if (EthernetInterface::connect())
    {
        result = __LINE__;
    }
    else
    {
        result = 0;
    }

    return result;
}
Ejemplo n.º 5
0
int main(void)
{
    pc.baud(115200);

    THREAD_HANDLE ThreadHandle;

    (void)printf("Initializing mbed specific things...\r\n");

    (void)printf("doing a one time EthernetInterface::init();\r\n");
    if (EthernetInterface::init() != 0)
    {
         (void)printf("Failed EthernetInterface::init();\r\n");
         return -1;
    }
    (void)printf("done doing a one time EthernetInterface::init();\r\n");

    if (setupRealTime() != 0)
    {
         (void)printf("Failed setting up real time clock\r\n");
         return -1;
    }

    /* clear the LED light upon startup */
    red_led = 1;
    blue_led = 1;
    green_led = 1;

    alarm_type = ALARM_NONE;
    led_on = 0;

    /* clear the screen */
    lcd.cls();

    if (ThreadAPI_Create(&ThreadHandle, LED_Update_Thread, NULL) != THREADAPI_OK)
    {
        (void)printf("Error spinning LED update thread.\r\n");
        return -1;
    }

    /* initialize the IoTHubClient */
    if (serializer_init(NULL) != SERIALIZER_OK)
    {
        (void)printf("Failed on serializer_init\r\n");
    }
    else
    {
        /* Setup IoTHub client configuration */

        IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle = IoTHubClient_LL_CreateFromConnectionString(connectionString, HTTP_Protocol);

        if (iotHubClientHandle == NULL)
        {
            (void)printf("Failed on IoTHubClient_Create\r\n");
        }
        else
        {
            unsigned int minimumPollingTime = 9; /*because it can poll "after 9 seconds" polls will happen effectively at ~10 seconds*/
            if (IoTHubClient_LL_SetOption(iotHubClientHandle, "MinimumPollingTime", &minimumPollingTime) != IOTHUB_CLIENT_OK)
            {
                printf("failure to set option \"MinimumPollingTime\"\r\n");
            }

            FrdmDevice* frdmDevice = CREATE_MODEL_INSTANCE(Contoso, FrdmDevice, true);
            if (frdmDevice == NULL)
            {
                (void)printf("Failed on CREATE_MODEL_INSTANCE\r\n");
            }
            else
            {
                IOTHUB_CLIENT_RESULT setMessageResult = IoTHubClient_LL_SetMessageCallback(iotHubClientHandle, IoTHubMessage, frdmDevice);
                if (setMessageResult != IOTHUB_CLIENT_OK)
                {
                    (void)printf("unable to IoTHubClient_SetMessageCallback\r\n");
                }
                else
                {
                    STRING_HANDLE commandsMetadata;

                    temp = (sensor.temp() * 9 / 5) + 32;

                    /* send the device info upon startup so that the cloud app knows
                    what commands are available and the fact that the device is up */
                    frdmDevice->ObjectType = "DeviceInfo-HW";
                    frdmDevice->ObjectName = "An ALARM device";
                    frdmDevice->Version = "1.0";
                    frdmDevice->SystemProperties.DeviceID = (char*)deviceId;
                    frdmDevice->SystemProperties.Enabled = true;

                    /* build the description of the commands on the device */
                    commandsMetadata = STRING_new();
                    if (commandsMetadata == NULL)
                    {
                        (void)printf("Failed on creating string for commands metadata\r\n");
                    }
                    else
                    {
                        /* Serialize the commands metadata as a JSON string before sending */
                        if (SchemaSerializer_SerializeCommandMetadata(GET_MODEL_HANDLE(Contoso, FrdmDevice), commandsMetadata) != SCHEMA_SERIALIZER_OK)
                        {
                            (void)printf("Failed serializing commands metadata\r\n");
                        }
                        else
                        {
                            frdmDevice->Commands = (char*)STRING_c_str(commandsMetadata);

                            /* Send the device information and commands metadata to the cloud */
                            {
                                unsigned char* destination;
                                size_t destinationSize;
                                if (SERIALIZE(&destination, &destinationSize, frdmDevice->ObjectName, frdmDevice->ObjectType, frdmDevice->SystemProperties, frdmDevice->Version, frdmDevice->Commands) != IOT_AGENT_OK)
                                {
                                    (void)printf("Failed to serialize\r\n");
                                }
                                else
                                {
                                    sendMessage(iotHubClientHandle, destination, destinationSize);
                                    free(destination);
                                }
                            }
                        }

                        STRING_delete(commandsMetadata);
                    }

                    frdmDevice->ObjectName = (ascii_char_ptr)deviceId;
                    frdmDevice->ObjectType = "SensorTagEvent";
                    frdmDevice->Version = "1.0";
                    frdmDevice->TargetAlarmDevice = (ascii_char_ptr)deviceId;

                    while (1)
                    {
                        unsigned char* destination;
                        size_t destinationSize;

                        (void)printf("Sending %.02f\r\n", temp);
                        frdmDevice->temp = temp;

                        if (SERIALIZE(&destination, &destinationSize, frdmDevice->ObjectName, frdmDevice->ObjectType, frdmDevice->Version, frdmDevice->TargetAlarmDevice, frdmDevice->temp) != IOT_AGENT_OK)
                        {
                            (void)printf("Failed to serialize\r\n");
                        }
                        else
                        {
                            sendMessage(iotHubClientHandle, destination, destinationSize);
                            free(destination);
                        }

                        /* schedule IoTHubClient to send events/receive commands */
                        IoTHubClient_LL_DoWork(iotHubClientHandle);
                    }
                }
                DESTROY_MODEL_INSTANCE(frdmDevice);
            }
            IoTHubClient_LL_Destroy(iotHubClientHandle);
        }
        serializer_deinit();
    }
}