// Copyright 2015 by Thorsten von Eicken, see LICENSE.txt #include #include "config.h" #include "serled.h" #include "cgiwifi.h" #include "tcpclient.h" //===== "CONN" LED status indication static ETSTimer ledTimer; // Set the LED on or off, respecting the defined polarity static void ICACHE_FLASH_ATTR setLed(int on) { int8_t pin = flashConfig.conn_led_pin; if (pin < 0) return; // disabled // LED is active-low if (on) { gpio_output_set(0, (1<= 0) return; // not connected or other error // compose TCP command uint8_t chan = MAX_TCP_CHAN-1; tcpClientCommand(chan, 'T', "grovestreams.com:80"); // compose http header char buf[1024]; int hdrLen = os_sprintf(buf, "PUT /api/feed?api_key=%s HTTP/1.0\r\n" "Content-Type: application/json\r\n" "Content-Length: XXXXX\r\n\r\n", flashConfig.api_key); // http body int dataLen = os_sprintf(buf+hdrLen, "[{\"compId\":\"%s\", \"streamId\":\"%s\", \"data\":%d}]\r", flashConfig.hostname, GS_STREAM, rssi); buf[hdrLen+dataLen++] = 0; buf[hdrLen+dataLen++] = '\n'; // hackish way to fill in the content-length os_sprintf(buf+hdrLen-9, "%5d", dataLen); buf[hdrLen-4] = '\r'; // fix-up the \0 inserted by sprintf (hack!) // send the request off and forget about it... for (short i=0; i= 0) { makeGpio(flashConfig.conn_led_pin); setLed(1); } os_printf("CONN led=%d\n", flashConfig.conn_led_pin); os_timer_disarm(&ledTimer); os_timer_setfn(&ledTimer, ledTimerCb, NULL); os_timer_arm(&ledTimer, 2000, 0); os_timer_disarm(&rssiTimer); os_timer_setfn(&rssiTimer, rssiTimerCb, NULL); os_timer_arm(&rssiTimer, RSSI_INTERVAL, 1); // recurring timer }