Copyright ©

Mongoose OS Forum

ATTENTION! This forum has moved to:

Do not post any new messages.

How to use http Put-Methode to Control Philips Hue Light

Goal: Switch on/off my Philips Hue Light. Control it through my Philips Hue Hub with Address where the lamp represent as an Ressource.
All I have to do is to send a PUT Message with Message Body {"on":true} on the Ressource “

Suppose “http_client.c” is a good start Code for this job. But have no idea without better example.
Can anyone give an example or guide me to a starting point.
Thanks a lot!

     * Copyright (c) 2014 Cesanta Software Limited
     * All rights reserved
     * This program fetches HTTP URLs.

    #include "mongoose.h"

    static int s_exit_flag = 0;
    static int s_show_headers = 0;

    static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
      struct http_message *hm = (struct http_message *) ev_data;

      switch (ev) {
        case MG_EV_CONNECT:
          if (*(int *) ev_data != 0) {
            fprintf(stderr, "connect() failed: %s\n", strerror(*(int *) ev_data));
            s_exit_flag = 1;
        case MG_EV_HTTP_REPLY:
          nc->flags |= MG_F_CLOSE_IMMEDIATELY;
          if (s_show_headers) {
            fwrite(hm->message.p, 1, hm->message.len, stdout);
          } else {
            fwrite(hm->body.p, 1, hm->body.len, stdout);
          s_exit_flag = 1;
        case MG_EV_CLOSE:
          if(s_exit_flag == 0) {
            printf("Server closed connection\n");
            s_exit_flag = 1;

    int main(int argc, char *argv[]) {
      struct mg_mgr mgr;
      int i;
      mg_mgr_init(&mgr, NULL);

      mg_connect_http(&mgr, ev_handler, "", NULL, NULL);

      while (s_exit_flag == 0) {
        mg_mgr_poll(&mgr, 1000);

      return 0;
Sign In or Register to comment.