Navigation

    • Register
    • Login
    • Search
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. Cliff Karlsson
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Cliff Karlsson

    @Cliff Karlsson

    22
    Reputation
    399
    Posts
    2230
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    Cliff Karlsson Follow

    Best posts made by Cliff Karlsson

    • RE: My Slim 2AA Battery Node

      @m26872 I am fairly sure that all methods work in normal cases but nothing worked for me fore some reason 🙂 .

      The only way I could get it to work was when I finaly put the chip in an Arduino Uno clone with 328p Dip(?) socket and connected an USBtiny ISP to the ISCP of that Uno. It took just a couple of seconds and then it was done :).

      I flashed like 6-7 ships right away with bootloader and blink-sketch just for fun. Biggest problem now is to get the damn chip in/out of the sockets without bending any legs. But I ordered a chip extractor to remedy that problem (in 4-6 weeks :()

      posted in My Project
      Cliff Karlsson
      Cliff Karlsson
    • RE: What is wrong with this sketch?

      ahh!!!, you where right. I powered the node using a mobile charger but had not connected the PIR to the same GND as the charger. Now it works.

      posted in Troubleshooting
      Cliff Karlsson
      Cliff Karlsson
    • RE: 💬 Arduino Pro Mini Shield for RFM69(H)W

      Are there any more files for this board?

      posted in OpenHardware.io
      Cliff Karlsson
      Cliff Karlsson
    • Is it better to use RFM69HW/Nrf24L01 long-range on gateway?

      I have not quite figured out if there is any advantage to use the long range variants of radios on the gateway. If I for example use a Nrf24L01 long range with antenna, will I get stronger readings? or is the long range versions only good for sending data?

      posted in General Discussion
      Cliff Karlsson
      Cliff Karlsson
    • RE: 50mm x 50mm board with different powering options

      Thanks for the link. But I can barely solder regular components, it looks like I need to place some smd stuff on that board, I have seen crackheads on cops that have more stable hands than me.

      posted in My Project
      Cliff Karlsson
      Cliff Karlsson
    • RE: Energy Monitoring

      Sorry for spamming but I solved the problem. The Original sketch was fine. I removed the radio and resoldered it (RFM69W) And then everything was Ok. There must have been some bad connecton as the sketch sent 3x greeting message.

      posted in Troubleshooting
      Cliff Karlsson
      Cliff Karlsson
    • RE: 💬 MySWeMosGWShield - WeMos Mini MySensors Gateway Shield

      Sometimes my own stupidity still amazes me. The pins of all my wemos where soldered at the oposite side as the ones in your examples. all the radios then got powered using 5v instead of 3.3v, not very suprising that the nrf radios got hot as h*ll and that nothing worked as it should.

      Suprisingly the RFM69 seams to have survived. I guess the smd nrf24 all are toast.

      Everything works perfekt now when I connected it correctly 🙂

      posted in OpenHardware.io
      Cliff Karlsson
      Cliff Karlsson
    • RE: Help with script for controlling Wemo bulbs.

      @drock1985
      I have tried Ouimeaux but it was to slow for my liking. I have placed an arduino behind the a wallswitch that controls a wemo led that is alway powered. When I last tried Ouimeaux the reactiontime was around 5 seconds and my kids and wife would have flicked the switch 5-6 times before any reactions was seen.

      I then moved over to installing wemo manager + server on an android witch makes the reaction time go down to about 1-2 sec. But I must say that I would want the reaction time to be under 1 sec.

      posted in General Discussion
      Cliff Karlsson
      Cliff Karlsson
    • RE: My own board (50mm x 30mm)

      Is it possible to order the AC boards from your last picture?

      posted in My Project
      Cliff Karlsson
      Cliff Karlsson
    • RE: Help troubleshoting sketch

      Yes I have tried adding a sensor using the dev-branch and the # define My_Radio_RFM69 option

      posted in Troubleshooting
      Cliff Karlsson
      Cliff Karlsson

    Latest posts made by Cliff Karlsson

    • People counter using VL53L1X help "decoding" existing code to arduino

      I stumbled upon this video that I think is really cool. I then found a forum thread on the ST website where an ST employee responded that he could send the code by email. After getting the code I realized that the code was made for some other system (STM32?). Could anyone look at the code and see if it is possible to port so it would be usable using an Arduino/ESP32/ESP8266 ?

      Code

      People Counting Using a Single ST Time-of-Flight Sensor – 02:11
      — STMicroelectronics

      I think I found the code

      /**
        ******************************************************************************
        * File Name          : main.c
        * Description        : Main program body
        ******************************************************************************
        *
        * COPYRIGHT(c) 2017 STMicroelectronics
        *
        * Redistribution and use in source and binary forms, with or without modification,
        * are permitted provided that the following conditions are met:
        *   1. Redistributions of source code must retain the above copyright notice,
        *      this list of conditions and the following disclaimer.
        *   2. Redistributions in binary form must reproduce the above copyright notice,
        *      this list of conditions and the following disclaimer in the documentation
        *      and/or other materials provided with the distribution.
        *   3. Neither the name of STMicroelectronics nor the names of its contributors
        *      may be used to endorse or promote products derived from this software
        *      without specific prior written permission.
        *
        * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
        * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
        * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
        * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        *
        ******************************************************************************
        */
      	
      /* Includes ------------------------------------------------------------------*/
      #include "stm32xxx_hal.h"
      
      /* USER CODE BEGIN Includes */
      #include "main.h"
      #include "VL53L1X_API.h"
      #include "VL53l1X_calibration.h"
      #include "X-NUCLEO-53L1A1.h"
      /* USER CODE END Includes */
      /* Private variables ---------------------------------------------------------*/
      /* USER CODE BEGIN PV */
      /* Private variables ---------------------------------------------------------*/
      I2C_HandleTypeDef hi2c1;
      UART_HandleTypeDef huart2;
      VL53L1_Dev_t                   dev;
      int status = 0;
      volatile int IntCount;
      #define isInterrupt 1 /* If isInterrupt = 1 then device working in interrupt mode, else device working in polling mode */
      /* USER CODE END PV */
      
      /* Private function prototypes -----------------------------------------------*/
      /* USER CODE BEGIN PFP */
      /* Private function prototypes -----------------------------------------------*/
      int SystemClock_Config(void);
      static void MX_GPIO_Init(void);
      static int MX_USART2_UART_Init(void);
      static int MX_I2C1_Init(void);
      /* USER CODE END PFP */
      
      /* USER CODE BEGIN 0 */
      #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
      
      // People Counting defines
      #define NOBODY 0
      #define SOMEONE 1
      #define LEFT 0
      #define RIGHT 1
      
      #define DIST_THRESHOLD_MAX  1780
      
      
      PUTCHAR_PROTOTYPE
      {
      	HAL_UART_Transmit(&huart2, (uint8_t*)&ch, 1, 0xFFFF);
      	return ch;
      }
      
      void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
      {
      	if (GPIO_Pin==VL53L1X_INT_Pin)
      	{
      		IntCount++;
      	}
      }
      
      /* USER CODE END 0 */
      
      
      
      int ProcessPeopleCountingData(int16_t Distance, uint8_t zone) {
      
      	static char PeopleCountString[4];
          static int PathTrack[] = {0,0,0,0};
          static int PathTrackFillingSize = 1; // init this to 1 as we start from state where nobody is any of the zones
          static int LeftPreviousStatus = NOBODY;
          static int RightPreviousStatus = NOBODY;
          static int PeopleCount = 0;
      
          int CurrentZoneStatus = NOBODY;
          int AllZonesCurrentStatus = 0;
          int AnEventHasOccured = 0;
      
      	if (Distance < DIST_THRESHOLD_MAX) {
      		// Someone is in !
      		CurrentZoneStatus = SOMEONE;
      	}
      
      	// left zone
      	if (zone == LEFT) {
      
      		if (CurrentZoneStatus != LeftPreviousStatus) {
      			// event in left zone has occured
      			AnEventHasOccured = 1;
      
      			if (CurrentZoneStatus == SOMEONE) {
      				AllZonesCurrentStatus += 1;
      			}
      			// need to check right zone as well ...
      			if (RightPreviousStatus == SOMEONE) {
      				// event in left zone has occured
      				AllZonesCurrentStatus += 2;
      			}
      			// remember for next time
      			LeftPreviousStatus = CurrentZoneStatus;
      		}
      	}
      	// right zone
      	else {
      
      		if (CurrentZoneStatus != RightPreviousStatus) {
      
      			// event in left zone has occured
      			AnEventHasOccured = 1;
      			if (CurrentZoneStatus == SOMEONE) {
      				AllZonesCurrentStatus += 2;
      			}
      			// need to left right zone as well ...
      			if (LeftPreviousStatus == SOMEONE) {
      				// event in left zone has occured
      				AllZonesCurrentStatus += 1;
      			}
      			// remember for next time
      			RightPreviousStatus = CurrentZoneStatus;
      		}
      	}
      
      	// if an event has occured
      	if (AnEventHasOccured) {
      		if (PathTrackFillingSize < 4) {
      			PathTrackFillingSize ++;
      		}
      
      		// if nobody anywhere lets check if an exit or entry has happened
      		if ((LeftPreviousStatus == NOBODY) && (RightPreviousStatus == NOBODY)) {
      
      			// check exit or entry only if PathTrackFillingSize is 4 (for example 0 1 3 2) and last event is 0 (nobobdy anywhere)
      			if (PathTrackFillingSize == 4) {
      				// check exit or entry. no need to check PathTrack[0] == 0 , it is always the case
      
      				if ((PathTrack[1] == 1)  && (PathTrack[2] == 3) && (PathTrack[3] == 2)) {
      					// This an entry
      					PeopleCount ++;
                          sprintf(PeopleCountString, "%d", PeopleCount);
                          XNUCLEO53L1A1_SetDisplayString(PeopleCountString);
      
      				} else if ((PathTrack[1] == 2)  && (PathTrack[2] == 3) && (PathTrack[3] == 1)) {
      					// This an exit
      					PeopleCount --;
                          sprintf(PeopleCountString, "%d", PeopleCount);
                          XNUCLEO53L1A1_SetDisplayString(PeopleCountString);
      				}
      			}
      
      			PathTrackFillingSize = 1;
      		}
      		else {
      			// update PathTrack
      			// example of PathTrack update
      			// 0
      			// 0 1
      			// 0 1 3
      			// 0 1 3 1
      			// 0 1 3 3
      			// 0 1 3 2 ==> if next is 0 : check if exit
      			PathTrack[PathTrackFillingSize-1] = AllZonesCurrentStatus;
      		}
      	}
      
      	// output debug data to main host machine
      	return(PeopleCount);
      
      }
      
      int main(void)
      {
      	int8_t error;
          uint8_t byteData, sensorState=0;
          uint16_t wordData;
          uint16_t Distance;
          uint8_t RangeStatus;
          uint8_t dataReady;
          int center[2] = {167,231}; /* these are the spad center of the 2 8*16 zones */
          int Zone = 0;
          int PplCounter = 0;
          
          /* MCU Configuration----------------------------------------------------------*/
          
          /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
          HAL_Init();
          
          /* Configure the system clock */
          error = SystemClock_Config();
          
          /* Initialize all configured peripherals */
          MX_GPIO_Init();
          error += MX_USART2_UART_Init();
          error += MX_I2C1_Init();
          
          if (error != 0)
          {
              printf("Could not initialize the nucleo board\n");
              return -1;
          }
      
          XNUCLEO53L1A1_Init();
          dev.I2cHandle = &hi2c1;
          dev.I2cDevAddr = 0x52;
         
          status = XNUCLEO53L1A1_ResetId(XNUCLEO53L1A1_DEV_LEFT, 0); // Reset ToF sensor
          HAL_Delay(2);
          status = XNUCLEO53L1A1_ResetId(XNUCLEO53L1A1_DEV_CENTER, 0); // Reset ToF sensor
          HAL_Delay(2);
          status = XNUCLEO53L1A1_ResetId(XNUCLEO53L1A1_DEV_RIGHT, 0); // Reset ToF sensor
          HAL_Delay(2);
          status = XNUCLEO53L1A1_ResetId(XNUCLEO53L1A1_DEV_LEFT, 1); // Reset ToF sensor
          HAL_Delay(2);
          
          // Those basic I2C read functions can be used to check your own I2C functions */
          status = VL53L1_RdByte(&dev, 0x010F, &byteData);
          printf("VL53L1X Model_ID: %X\n", byteData);
          status = VL53L1_RdByte(&dev, 0x0110, &byteData);
          printf("VL53L1X Module_Type: %X\n", byteData);
          status = VL53L1_RdWord(&dev, 0x010F, &wordData);
          printf("VL53L1X: %X\n", wordData);
          while (sensorState == 0) {
              status = VL53L1X_BootState(dev, &sensorState);
              HAL_Delay(2);
          }
         
          printf("Chip booted\n");
          
          /* Init 4 digit display */
          XNUCLEO53L1A1_SetDisplayString("0");
      
          /* Initialize and configure the device according to people counting need */
          status = VL53L1X_SensorInit(dev);
          status += VL53L1X_SetDistanceMode(dev, 2); /* 1=short, 2=long */
          status += VL53L1X_SetTimingBudgetInMs(dev, 20); /* in ms possible values [20, 50, 100, 200, 500] */
          status += VL53L1X_SetInterMeasurementInMs(dev, 20); 
          status += VL53L1X_SetROI(dev, 8, 16); /* minimum ROI 4,4 */
          if (status != 0) {
              printf("Error in Initalisation or configuration of the device\n");
              return (-1);
          }
          
          printf("Start counting people  ...\n");
          status = VL53L1X_StartRanging(dev);   /* This function has to be called to enable the ranging */
          
          while(1) { /* read and display data */
              while (dataReady == 0) {
      			status = VL53L1X_CheckForDataReady(dev, &dataReady);
      			HAL_Delay(2);
              }
          
      		dataReady = 0;
      		status += VL53L1X_GetRangeStatus(dev, &RangeStatus);
      		status += VL53L1X_GetDistance(dev, &Distance);
      		status += VL53L1X_ClearInterrupt(dev); /* clear interrupt has to be called to enable next interrupt*/
      		if (status != 0) {
      			printf("Error in operating the device\n");
      			return (-1);
      		}
      
      		// wait a couple of milliseconds to ensure the setting of the new ROI center for the next ranging is effective
      		// otherwise there is a risk that this setting is applied to current ranging (even if timing has expired, the intermeasurement
      		// may expire immediately after.
      		HAL_Delay(10);
      		status = VL53L1X_SetROICenter(dev, center[Zone]);
      		if (status != 0) {
      			printf("Error in chaning the center of the ROI\n");
      			return (-1);
      		}
      
      		// inject the new ranged distance in the people counting algorithm
      		PplCounter = ProcessPeopleCountingData(Distance, Zone);
      
      		Zone++;
      		Zone = Zone%2;
      
      		printf("%d, %d, %d, %d\n", Zone, RangeStatus, Distance, PplCounter);
          }
      }
      
      /** System Clock Configuration
      */
      #ifdef STM32F401xE
      
      int SystemClock_Config(void)
      {
      
          RCC_OscInitTypeDef RCC_OscInitStruct;
          RCC_ClkInitTypeDef RCC_ClkInitStruct;
        
          /**Configure the main internal regulator output voltage 
          */
          __HAL_RCC_PWR_CLK_ENABLE();
        
          __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
        
          /**Initializes the CPU, AHB and APB busses clocks 
          */
          RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
          RCC_OscInitStruct.HSIState = RCC_HSI_ON;
          RCC_OscInitStruct.HSICalibrationValue = 16;
          RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
          RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
          RCC_OscInitStruct.PLL.PLLM = 16;
          RCC_OscInitStruct.PLL.PLLN = 336;
          RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
          RCC_OscInitStruct.PLL.PLLQ = 7;
          if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
          {
              return -1;
          }
        
          /**Initializes the CPU, AHB and APB busses clocks 
          */
          RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                                      |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
          RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
          RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
          RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
          RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
        
          if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
          {
              return -1;
          }
        
          /**Configure the Systick interrupt time 
          */
          HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
        
          /**Configure the Systick 
          */
          HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
        
          /* SysTick_IRQn interrupt configuration */
          HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
        
          return 0;
      }
      #endif
      
      
      #ifdef STM32F401xE
      
      /* I2C1 init function */
      static int MX_I2C1_Init(void)
      {
          hi2c1.Instance = I2C1;
          hi2c1.Init.ClockSpeed = 100000;
          hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
          hi2c1.Init.OwnAddress1 = 0;
          hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
          hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
          hi2c1.Init.OwnAddress2 = 0;
          hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
          hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
          if (HAL_I2C_Init(&hi2c1) != HAL_OK)
          {
            return -1;
          }
          
          return 0;
      
      }
      #endif
      
      /* USART2 init function */
      int MX_USART2_UART_Init(void)
      {
      
          huart2.Instance = USART2;
          huart2.Init.BaudRate = 460800;
          huart2.Init.WordLength = UART_WORDLENGTH_8B;
          huart2.Init.StopBits = UART_STOPBITS_1;
          huart2.Init.Parity = UART_PARITY_NONE;
          huart2.Init.Mode = UART_MODE_TX_RX;
          huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
          huart2.Init.OverSampling = UART_OVERSAMPLING_16;
          if (HAL_UART_Init(&huart2) != HAL_OK)
          {
              return (-1);
          }
          return 0;
      
      }
      
      /** Configure pins as 
              * Analog 
              * Input 
              * Output
              * EVENT_OUT
              * EXTI
      */
      static void MX_GPIO_Init(void)
      {
      
          GPIO_InitTypeDef GPIO_InitStruct;
         
          /* GPIO Ports Clock Enable */
          __HAL_RCC_GPIOC_CLK_ENABLE();
          __HAL_RCC_GPIOH_CLK_ENABLE();
          __HAL_RCC_GPIOA_CLK_ENABLE();
          __HAL_RCC_GPIOB_CLK_ENABLE();
         
          /*Configure GPIO pin Output Level */
          HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);
         
          /*Configure GPIO pin : B1_Pin */
          GPIO_InitStruct.Pin = B1_Pin;
          GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
          GPIO_InitStruct.Pull = GPIO_NOPULL;
          HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);
         
          /*Configure GPIO pin : VL53L1X_INT_Pin */
          GPIO_InitStruct.Pin = VL53L1X_INT_Pin;
          GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
          GPIO_InitStruct.Pull = GPIO_PULLUP;
          HAL_GPIO_Init(VL53L1X_INT_GPIO_Port, &GPIO_InitStruct);
         
          /*Configure GPIO pin : LD2_Pin */
          GPIO_InitStruct.Pin = LD2_Pin;
          GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
          GPIO_InitStruct.Pull = GPIO_NOPULL;
          GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
          HAL_GPIO_Init(LD2_GPIO_Port, &GPIO_InitStruct);
         
          /* EXTI interrupt init*/
          HAL_NVIC_SetPriority(EXTI4_IRQn, 0, 0);
          HAL_NVIC_EnableIRQ(EXTI4_IRQn);
      
      }
      
      
      /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
      
      
      posted in General Discussion
      Cliff Karlsson
      Cliff Karlsson
    • Help understanding why websockets does not work in arduino sketch

      have taken som existing code which reads a sensor and outputs to a webserver using websockets (running on an ESP8266) that connects to a wifi-network. I tried to modify the code so that instead of connecting to an existing wifi it creates a AP that I can connect to login to the webserver to show the data.

      I can connect to the AP and also connect to the webserver after logging in to the AP. But ít only shows a empty table. If I look at the serial monitor the sensor outputs all data correctly.

      Have I done anything wrong modifying the code?

      
      // ESP8266 Pins
      //  4(SDA) --- AMG8833 SDA
      //  5(SCL) --- AMG8833 SCL
      //  13     --- LED (Anode) via 100ohm
      
      #include <pgmspace.h>
      #include <ESP8266WiFi.h>
      #include <WiFiClient.h>
      #include <ESP8266WebServer.h>
      #include <WebSocketsServer.h>
      #include <ESP8266mDNS.h>
      #include <ArduinoOTA.h>
      #include <Wire.h>
      #include <Adafruit_AMG88xx.h>
      
      Adafruit_AMG88xx amg;
      
      const char* ssid = "Jacksson";
      const char* password = "mandelvatten";
      
      const int pin_led = 13;
      
      ESP8266WebServer server(80);
      WebSocketsServer webSocket(81);
      
      void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) {
        switch (type) {
          case WStype_DISCONNECTED:
            Serial.printf("[%u] Disconnected!\n", num);
            break;
          case WStype_CONNECTED:
            IPAddress ip = webSocket.remoteIP(num);
            Serial.printf("[%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload);
            break;
        }
      }
      
      void toggle() {
        static bool last_led = false;
        last_led = !last_led;
        digitalWrite(pin_led, last_led);
      }
      
      void handleRoot() {
       auto ip = WiFi.localIP();
       String ip_str = String(ip[0]) + "." + ip[1] + "." + ip[2] + "." + ip[3];
       server.send(200, "text/html", String(ws_html_1()) +  ip_str + ws_html_2());
       // server.send(200, "text/html", "<h1>You are connected</h1>");
      }
      
      void handleNotFound() {
        String message = "File Not Found\n\n";
        message += "URI: ";
        message += server.uri();
        message += "\nMethod: ";
        message += (server.method() == HTTP_GET)?"GET":"POST";
        message += "\nArguments: ";
        message += server.args();
        message += "\n";
        for (uint8_t i = 0; i<server.args(); i++){
          message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
        }
        server.send(404, "text/plain", message);
      }
      
      void WiFiEvent(WiFiEvent_t event) {
          switch(event) {
            
            case WIFI_EVENT_STAMODE_DISCONNECTED:
              digitalWrite(pin_led, LOW);
              Serial.println("WiFi lost connection: reconnecting...");
              WiFi.begin();
              break;
            case WIFI_EVENT_STAMODE_CONNECTED:
              Serial.print("Connected to ");
              Serial.println(ssid);
              break;
            case WIFI_EVENT_STAMODE_GOT_IP:
              digitalWrite(pin_led, HIGH);
              Serial.print("IP address: ");
              Serial.println(WiFi.localIP());
              if (MDNS.begin("esp8266-amg8833")) {
                Serial.println("MDNS responder started");
              }
              enableOTA();
              break;
          }
      }
      
      void enableOTA() {
        // Port defaults to 8266
        // ArduinoOTA.setPort(8266);
      
        // Hostname defaults to esp8266-[ChipID]
        // ArduinoOTA.setHostname("myesp8266");
      
        // No authentication by default
        // ArduinoOTA.setPassword((const char *)"123");
      
        ArduinoOTA.onStart([]() {
          Serial.println("Start");
        });
        ArduinoOTA.onEnd([]() {
          Serial.println("\nEnd");
        });
        ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
          Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
        });
        ArduinoOTA.onError([](ota_error_t error) {
          Serial.printf("Error[%u]: ", error);
          if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
          else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
          else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
          else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
          else if (error == OTA_END_ERROR) Serial.println("End Failed");
        });
        ArduinoOTA.begin();
      }
      
      void setup(void) {
       delay(1000);
        Serial.begin(115200);
        Serial.println();
        Serial.print("Configuring access point...");
        /* You can remove the password parameter if you want the AP to be open. */
        WiFi.softAP(ssid, password);
      
        IPAddress myIP = WiFi.softAPIP();
        Serial.print("AP IP address: ");
        Serial.println(myIP);
        server.on("/", handleRoot);
        server.begin();
        Serial.println("HTTP server started");
      
        server.on("/current", [](){
          String str;
          server.send(200, "text/plain", get_current_values_str(str));
        });
      
        server.onNotFound(handleNotFound);
      
        server.begin();
      
        webSocket.begin();
        webSocket.onEvent(webSocketEvent);
      
        Serial.println("HTTP server started");
      
        amg.begin(0x69);
        delay(100); // let sensor boot up
      }
      
      void loop(void) {
        ArduinoOTA.handle();
        server.handleClient();
        webSocket.loop();
      
       
      
        static unsigned long last_read_ms = millis();
        unsigned long now = millis();
        if (now - last_read_ms > 100) {
          last_read_ms += 100;
          String str;
          get_current_values_str(str);
          Serial.println(str);
          webSocket.broadcastTXT(str);
        }
      }
      
      String& get_current_values_str(String& ret)
      {
        float pixels[AMG88xx_PIXEL_ARRAY_SIZE];
        amg.readPixels(pixels);
        ret = "[";
        for(int i = 0; i < AMG88xx_PIXEL_ARRAY_SIZE; i++) {
          if( i % 8 == 0 ) ret += "\r\n";
          ret += pixels[i];
          if (i != AMG88xx_PIXEL_ARRAY_SIZE - 1) ret += ", ";
        }
        ret += "\r\n]\r\n";
        return ret;
      }
      
      const __FlashStringHelper* ws_html_1() {
        return F("<!DOCTYPE html>\n"
          "<html>\n"
          "<head>\n"
          "<title>thermo</title>\n"
          "<style>\n"
          "body {\n"
          "    background-color: #667;\n"
          "}\n"
          "table#tbl td {\n"
          "    width: 64px;\n"
          "    height: 64px;\n"
          "    border: solid 1px grey;\n"
          "    text-align: center;\n"
          "}\n"
          "</style>\n"
          "</head>\n"
          "<body>\n"
          "<h1>Exjobbsgrejs</h1>"
          "<table border id=\"tbl\"></table>\n"
          "<script>\n"
          "function bgcolor(t) {\n"
          "    if (t < 0) t = 0;\n"
          "    if (t > 30) t = 30;\n"
          "    return \"hsl(\" + (360 - t * 12) + \", 100%, 80%)\";\n"
          "}\n"
          "\n"
          "var t = document.getElementById('tbl');\n"
          "var tds = [];\n"
          "for (var i = 0; i < 8; i++) {\n"
          "    var tr = document.createElement('tr');\n"
          "    for (var j = 0; j < 8; j++) {\n"
          "        var td = tds[i*8 + 7 - j] = document.createElement('td');\n"
          "        tr.appendChild(td);\n"
          "    }\n"
          "    t.appendChild(tr);\n"
          "}\n"
          "var connection = new WebSocket('ws://");
      }
      
      const __FlashStringHelper* ws_html_2() {
        return F(":81/');\n"
          "connection.onmessage = function(e) {\n"
          "    const data = JSON.parse(e.data);\n"
          "    for (var i = 0; i < 64; i++) {\n"
          "        tds[i].innerHTML = data[i].toFixed(2);\n"
          "        tds[i].style.backgroundColor = bgcolor(data[i]);\n"
          "    }\n"
          "};\n"
          "</script>\n"
          "</body>\n"
          "</html>\n");
      }
      
      
      posted in Troubleshooting
      Cliff Karlsson
      Cliff Karlsson
    • Is this scenario possible using domoticz?

      I have been planning to build/use a sensor with domoticz but my skills are pretty limited. But I am wondering if this is possible:

      I have a sensor whish can output four different values depending on how the sensor is triggered, how do I send four different values to domoticz and what sensor type do I chose? I want in this example be able to light up four different lightbulbs in domoticz depending on the sensoroutput.

      I would also want to be able to use a local variable and a global variable. Can I somehow "push" a variable from domoticz to the sensor everytime it changes?

      posted in Domoticz
      Cliff Karlsson
      Cliff Karlsson
    • Ninja spheres for sale (Sweden)

      Ok sorry if this is not allowed and just remove this post. But I have three Ninja spheres that I got from kickstarter a while a go. There supposed to be some super home-automation devices with zigbee/wlan/bluetooth (check the homepage for exact specs). But as alot of kickstarter campaigns this one crashed and burned and no development is done anymore.

      So the hardware is all cool and working but the software is dead i would think. It runs Ubuntu core I think and you can connect through ssh to fiddle around. I used it in the beginning to control my wemo lights directly from the sphere by swiping ontop of it. homepage
      I know I will never be able to use them for anything productive but maybee someone here can make some use of them. Give me a bid for one or all of them. I am not expecting a fortune...

      posted in General Discussion
      Cliff Karlsson
      Cliff Karlsson
    • RE: Help with sketch (motion/distance)

      I never understod how the millis() -part worked so I just changed it to a simple countdown instead.

      posted in Troubleshooting
      Cliff Karlsson
      Cliff Karlsson
    • RE: Help with sketch (motion/distance)

      @mfalkvidd Thanks for the help.
      I don't know why I had "INTERRUPT MOTION_A_TRIGGER_PIN-3" I think I originaly used pin2 for the motion sensor and when moving it to pin 3 I misunderstood and also changed that part from -2 to -3.

      Now most parts works as intended. But after triggering the motion sensor the distance-sensors fires for around 60s (Maybe the time it takes for the PIR to reset itself?)

      I only want the distance sensors to be active for 3s (unsigned long time = millis() + 30000;). How to I fix that?

      posted in Troubleshooting
      Cliff Karlsson
      Cliff Karlsson
    • RE: Help with sketch (motion/distance)

      Re: Help with sketch (motion/distance)

      I had some additional wiring problems so the distance sensors seams to work ok now. But It does not look like the motion-sensor part works.

      I was thinking that the sensor should sleep until motion but it should report the status to the controller every 120s so that domoticz etc. does not think that the sensor is dead.

      Now it starts the distance sensors directly on power and runs them for a long time and then sleeps. But I cant wake it up by moving my hand in front of it. I think it wakes up every 120s and spams the distance sensor then sleeps agin.

      0 MCO:BGN:INIT NODE,CP=RNNNA--,VER=2.1.1
      3 TSM:INIT
      4 TSF:WUR:MS=0
      11 TSM:INIT:TSP OK
      13 TSF:SID:OK,ID=2
      14 TSM:FPAR
      51 TSF:MSG:SEND,2-2-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      2058 !TSM:FPAR:NO REPLY
      2060 TSM:FPAR
      2096 TSF:MSG:SEND,2-2-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      2934 TSF:MSG:READ,0-0-2,s=255,c=3,t=8,pt=1,l=1,sg=0:0
      2939 TSF:MSG:FPAR OK,ID=0,D=1
      4104 TSM:FPAR:OK
      4105 TSM:ID
      4106 TSM:ID:OK
      4108 TSM:UPL
      4113 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
      4219 TSF:MSG:READ,0-0-2,s=255,c=3,t=25,pt=1,l=1,sg=0:1
      4224 TSF:MSG:PONG RECV,HP=1
      4227 TSM:UPL:OK
      4228 TSM:READY:ID=2,PAR=0,DIS=1
      4233 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
      4366 TSF:MSG:READ,0-0-2,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
      4373 TSF:MSG:SEND,2-2-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.1.1
      4381 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
      4648 TSF:MSG:READ,0-0-2,s=255,c=3,t=6,pt=0,l=1,sg=0:M
      4656 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=11,pt=0,l=22,sg=0,ft=0,st=OK:Distance+Motion Sensor
      4666 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.0
      4674 TSF:MSG:SEND,2-2-0-0,s=1,c=0,t=15,pt=0,l=0,sg=0,ft=0,st=OK:
      4715 !TSF:MSG:SEND,2-2-0-0,s=2,c=0,t=15,pt=0,l=0,sg=0,ft=0,st=NACK:
      4727 TSF:MSG:SEND,2-2-0-0,s=3,c=0,t=1,pt=0,l=0,sg=0,ft=1,st=OK:
      4733 MCO:REG:REQ
      4770 !TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=NACK:2
      6779 TSF:MSG:SEND,2-2-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=1,st=OK:2
      6848 TSF:MSG:READ,0-0-2,s=255,c=3,t=27,pt=1,l=1,sg=0:1
      6852 MCO:PIM:NODE REG=1
      6855 MCO:BGN:STP
      6856 MCO:BGN:INIT OK,TSP=1
      1
      6860 TSF:MSG:SEND,2-2-0-0,s=3,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:1
      Ping Sonar A: 0 cm
      Ping Sonar B: 15 cm
      6970 TSF:MSG:SEND,2-2-0-0,s=2,c=1,t=13,pt=2,l=2,sg=0,ft=0,st=OK:15
      Ping Sonar A: 123 cm
      6985 TSF:MSG:SEND,2-2-0-0,s=1,c=1,t=13,pt=2,l=2,sg=0,ft=0,st=OK:123
      Ping Sonar B: 15 cm
      Ping Sonar A: 126 cm
      7102 TSF:MSG:SEND,2-2-0-0,s=1,c=1,t=13,pt=2,l=2,sg=0,ft=0,st=OK:126
      Ping Sonar B: 15 cm
      Ping Sonar A: 125 cm
      7222 TSF:MSG:SEND,2-2-0-0,s=1,c=1,t=13,pt=2,l=2,sg=0,ft=0,st=OK:125
      Ping Sonar B: 15 cm
      Ping Sonar A: 125 cm
      Ping Sonar B: 15 cm
      Ping Sonar A: 126 cm
      7450 TSF:MSG:SEND,2-2-0-0,s=1,c=1,t=13,pt=2,l=2,sg=0,ft=0,st=OK:126
      Ping Sonar B: 15 cm
      Ping Sonar A: 125 cm
      7569 TSF:MSG:SEND,2-2-0-0,s=1,c=1,t=13,pt=2,l=2,sg=0,ft=0,st=OK:125
      Ping Sonar B: 15 cm
      Ping Sonar A: 125 cm
      Ping Sonar B: 15 cm
      Ping Sonar A: 125 cm
      Ping Sonar B: 15 cm
      Ping Sonar A: 124 cm
      35517 TSF:MSG:SEND,2-2-0-0,s=2,c=1,t=13,pt=2,l=2,sg=0,ft=0,st=OK:78
      Ping Sonar A: 80 cm
      35544 TSF:MSG:SEND,2-2-0-0,s=1,c=1,t=13,pt=2,l=2,sg=0,ft=0,st=OK:80
      Ping Sonar B: 74 cm
      35656 TSF:MSG:SEND,2-2-0-0,s=2,c=1,t=13,pt=2,l=2,sg=0,ft=0,st=OK:74
      Ping Sonar A: 132 cm
      35707 !TSF:MSG:SEND,2-2-0-0,s=1,c=1,t=13,pt=2,l=2,sg=0,ft=0,st=NACK:132
      Ping Sonar B: 79 cm
      ...
      35820 TSF:MSG:SEND,2-2-0-0,s=2,c=1,t=13,pt=2,l=2,sg=0,ft=1,st=OK:79
      35827 MCO:SLP:MS=200,SMS=0,I1=255,M1=255,I2=255,M2=255
      35831 MCO:SLP:TPD
      35833 MCO:SLP:WUP=-1
      35835 MCO:SLP:MS=120000,SMS=0,I1=0,M1=1,I2=255,M2=255
      35841 MCO:SLP:TPD
      
      posted in Troubleshooting
      Cliff Karlsson
      Cliff Karlsson
    • RE: Help with sketch (motion/distance)

      Thanks, well firstly the motion-sensor almost never triggers and when it finaly does I get only 0 or a few (1-2) readings from the Ultrasonic-sensor and it seams that only one of them gives me distance.

      posted in Troubleshooting
      Cliff Karlsson
      Cliff Karlsson
    • Connecting external power and FTDI adapter?

      I have a Arduino pro mini 5v where I have attached a couple of 5v sensors. I am using an external 5v powersupply and it is powering the sensors directly and also the arduino from the Vin/Gnd.

      I tried connecting the arduino to a 3.3v usb ftdi adapter without using the power supply to upload sketches and to use the serial monitor and it worked. But how do I power all the sensors from the power supply and also connect the ftdi-adapter at the same time without frying anything?

      posted in Troubleshooting
      Cliff Karlsson
      Cliff Karlsson
    • Help with sketch (motion/distance)

      Can anyone tell me how to fix this sketch so that it woorks correctly.

      I want the sensor to wake up when motion-sensor is triggered and start sending distance data from both Ultrasonic-sensors to controller for like 5s. Then back to sleep again until Motion is detected again.

      
      // Enable debug prints
      #define MY_DEBUG
      #define MY_BAUD_RATE 115200
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      #include <NewPing.h>
      #include <MySensors.h>
      #include <SPI.h>
      
      #define SONAR_A_CHILD_ID 1
      #define SONAR_B_CHILD_ID 2
      #define MOTION_A_CHILD_ID 3
      
      #define MOTION_A_TRIGGER_PIN  3
      
      #define SONAR_A_TRIGGER_PIN  5  // Arduino pin tied to trigger pin on the ultrasonic sensor.
      #define SONAR_A_ECHO_PIN     4 // Arduino pin tied to echo pin on the ultrasonic sensor.
      
      
      #define SONAR_B_TRIGGER_PIN  7  // Arduino pin tied to trigger pin on the ultrasonic sensor.
      #define SONAR_B_ECHO_PIN     6  // Arduino pin tied to echo pin on the ultrasonic sensor.
      
      #define MAX_DISTANCE 300 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
      unsigned long SLEEP_TIME = 200; // Sleep time between reads (in milliseconds)
      
      unsigned long MOTION_SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
      #define INTERRUPT MOTION_A_TRIGGER_PIN-3 // Usually the interrupt = pin -2 (on uno/nano anyway)
      
      
      NewPing sonar_A(SONAR_A_TRIGGER_PIN, SONAR_A_ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
      NewPing sonar_B(SONAR_B_TRIGGER_PIN, SONAR_B_ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
      
      
      MyMessage SONAR_A_msg(SONAR_A_CHILD_ID, V_DISTANCE);
      int SONAR_A_lastDist;
      
      MyMessage SONAR_B_msg(SONAR_B_CHILD_ID, V_DISTANCE);
      int SONAR_B_lastDist;
      
      MyMessage MOTION_A_msg(MOTION_A_CHILD_ID, V_TRIPPED);
      
      boolean metric = true; 
      
      void setup()  
      { 
        metric = getControllerConfig().isMetric; 
        pinMode(MOTION_A_TRIGGER_PIN, INPUT);      // sets the motion sensor digital pin as input
      }
      
      void presentation() {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Distance+Motion Sensor", "1.0");
      
        // Register all sensors to gw (they will be created as child devices)
        present(SONAR_A_CHILD_ID, S_DISTANCE);
        present(SONAR_B_CHILD_ID, S_DISTANCE);
        present(MOTION_A_TRIGGER_PIN, S_MOTION);
      }
      
      void loop()      
      {     
        
        boolean tripped = digitalRead(MOTION_A_TRIGGER_PIN) == HIGH; 
        
          
        Serial.println(tripped);
        send(MOTION_A_msg.set(tripped?"1":"0"));  // Send tripped value to gw 
       
       if(tripped)  {
        unsigned long time = millis()+30000;
        while (millis() < time){
            int SONAR_A_dist = metric?sonar_A.ping_cm():sonar_A.ping_in();
            Serial.print("Ping Sonar A: ");
            Serial.print(SONAR_A_dist); // Convert ping time to distance in cm and print result (0 = outside set distance range)
            Serial.println(metric?" cm":" in");
      
        if (SONAR_A_dist != SONAR_A_lastDist) {
            send(SONAR_A_msg.set(SONAR_A_dist));
            SONAR_A_lastDist = SONAR_A_dist;
            }
        
        wait(100);
      
            int SONAR_B_dist = metric?sonar_B.ping_cm():sonar_B.ping_in();
            Serial.print("Ping Sonar B: ");
            Serial.print(SONAR_B_dist); // Convert ping time to distance in cm and print result (0 = outside set distance range)
            Serial.println(metric?" cm":" in");
      
        if (SONAR_B_dist != SONAR_B_lastDist) {
            send(SONAR_B_msg.set(SONAR_B_dist));
            SONAR_B_lastDist = SONAR_B_dist;
            }
        
        }
        sleep(SLEEP_TIME);
      }
                  
      //else{
        // Sleep until interrupt comes in on motion sensor. Send update every two minute. 
        sleep(INTERRUPT,CHANGE, MOTION_SLEEP_TIME);
      //}
      }
      
      posted in Troubleshooting
      Cliff Karlsson
      Cliff Karlsson