Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
S

smilvert

@smilvert
About
Posts
38
Topics
5
Shares
0
Groups
0
Followers
1
Following
0

Posts

Recent Best Controversial

  • RFM95 RFM95:SWR:NACK
    S smilvert

    @lood29 When I use TTGO LORA as a dummy sensor (Node 10 in the above log) it always works without any nacks.

    The NACK only appears when I connect my own sensor (Node 140 in the log above).

    So Scenario 1
    Dummy sensor (TTGO LORA) <-> MQTT gateway (TTGO LORA) -> Works

    Scenario 2
    My sensor <-> MQTT gateway (TTGO LORA) -> NACK in the Gateway.

    Troubleshooting

  • RFM95 RFM95:SWR:NACK
    S smilvert

    Hi

    Im trying to setup a temperature sensor that should be placed at my jetty, 350 meters from my house. So I have chosen RFM95 as my radio, an E-ink display to show the temperature but I have some struggle to this setup. Need some debug help.

    As the controller I have a TTGO LORA.

    I have two of the TTGO LORA, One gateway and one debug sensor, so I can verify that thoose are working with mysensors but when I add my custom sensor I receives a lot of !RFM95:SWR:NACK from the Gateway.

    Sensor code:

    //#define MY_PASSIVE_NODE
    //#define PIN_SERIAL_TX       (8) 
    // Enable debug prints
    #define MY_DEBUG
    #define MY_DEBUG_VERBOSE_RFM95
    
    //#define   MY_DEBUG_VERBOSE_NRF5_ESB
    #define MY_NODE_ID 140
    //#define MY_GATEWAY_SERIAL
    
    
    #define MY_RFM95_RST_PIN 15
    #define MY_RFM95_IRQ_PIN 16
    #define MY_RFM95_IRQ_NUM MY_RFM95_IRQ_PIN
    #define DEFAULT_RFM95_CS_PIN      (SS)
    
    #define MY_RFM95_FREQUENCY (RFM95_434MHZ)
    // #define MY_RFM95_ATC_MODE_DISABLED
    #define MY_RFM95_ATC_TARGET_RSSI_DBM (-70)  // target RSSI -70dBm
    #define MY_RFM95_MAX_POWER_LEVEL_DBM (10)   // max. TX power 10dBm = 10mW
    
    #define RFM95_RETRY_TIMEOUT_MS 3000ul
    #define MY_TRANSPORT_STATE_TIMEOUT_MS 6*1000ul
    
    // Enable and select radio type attached
    //#define MY_RADIO_NRF24
    //#define MY_RADIO_NRF5_ESB
    //#define MY_RADIO_RFM69
    #define MY_RADIO_RFM95
    
    
    #include <MySensors.h>
    
    #define ENABLE_GxEPD2_GFX 1
    
    #include <GxEPD2_BW.h>
    #include <GxEPD2_3C.h>
    
    #include "Fonts/FreeMonoBold9pt7b.h" 
    #include "Fonts/FreeSerif18pt7b.h" 
    #include "Fonts/FreeSans18pt7b.h" 
    #include "Fonts/FreeSansBold24pt7b.h" 
    
    
    GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=5*/ 22, /*DC=*/ 24, /*RST=*/ -1, /*BUSY=*/ 19));
    
    #include "GxEPD2_boards_added.h"
    #include "bitmaps/Bitmaps200x200.h" // 1.54" b/w
    
    
    #define CHILD_ID_TEMP           (0)  
    #define CHILD_ID_HUM            (1)
    
    // ID of the sensor child
    #define CHILD_ID_UPLINK_QUALITY (2)
    #define CHILD_ID_TX_LEVEL       (3)
    #define CHILD_ID_TX_PERCENT     (4)
    #define CHILD_ID_TX_RSSI        (5)
    #define CHILD_ID_RX_RSSI        (6)
    #define CHILD_ID_TX_SNR         (7)
    #define CHILD_ID_RX_SNR         (8)
    
    
    // Initialize general message
    MyMessage msgTxRSSI(CHILD_ID_TX_RSSI, V_DISTANCE);
    MyMessage msgRxRSSI(CHILD_ID_RX_RSSI, V_DISTANCE);
    MyMessage msgTxSNR(CHILD_ID_TX_SNR, V_DISTANCE);
    MyMessage msgRxSNR(CHILD_ID_RX_SNR, V_DISTANCE);
    MyMessage msgTxLevel(CHILD_ID_TX_LEVEL, V_DISTANCE);
    MyMessage msgTxPercent(CHILD_ID_TX_PERCENT, V_DISTANCE);
    MyMessage msgUplinkQuality(CHILD_ID_UPLINK_QUALITY, V_DISTANCE);
    
    #define ledPin LED_BUILTIN
    // Initialize general message
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    
    float batteryVoltage = 0;
    float temperature = 0;
    int humidity = 0;
    int counter = 0;
    int switch_led = 1;
    
    void setup()
    {
      
      Serial.print("Display init");
      sleep(1000);
      hwPinMode(ledPin, OUTPUT_D0H1);
    
      NRF_CLOCK->INTENSET = B11; //enable interrupts for EVENTS_HFCLKSTARTED and  EVENTS_LFCLKSTARTED
      NRF_CLOCK->TASKS_HFCLKSTART = 1; //start the high frequency crystal oscillator clock
      while (!(NRF_CLOCK->EVENTS_HFCLKSTARTED)) {} //wait until high frequency crystal oscillator clock is up to speed and working
    
      pinMode(ledPin, OUTPUT);
      digitalWrite(ledPin, HIGH);
      display.init(115200);
      clearScreen();
    
    }
    
    void presentation()
    {
      // Send the sketch version information to the gateway and controller
      sendSketchInfo("Passive node", "1.1");
      // Register all sensors to gw (they will be created as child devices)
      present(CHILD_ID_TEMP, S_TEMP, "Temp");
      present(CHILD_ID_HUM, S_HUM, "Hum");
    
      present(CHILD_ID_UPLINK_QUALITY, S_DISTANCE, "UPLINK QUALITY RSSI");
      present(CHILD_ID_TX_LEVEL, S_DISTANCE, "TX LEVEL DBM");
      present(CHILD_ID_TX_PERCENT, S_DISTANCE, "TX LEVEL PERCENT");
      present(CHILD_ID_TX_RSSI, S_DISTANCE, "TX RSSI");
      present(CHILD_ID_RX_RSSI, S_DISTANCE, "RX RSSI");
      present(CHILD_ID_TX_SNR, S_DISTANCE, "TX SNR");
      present(CHILD_ID_RX_SNR, S_DISTANCE, "RX SNR");
    
    }
    
    void loop()
    {
    
      // generate some random data
      counter ++;
      if (counter == 10 ) {
        temperature = 0;
        humidity = 0;
        counter = 0;
      }
      else
      {
        temperature = 25.0 + random(0, 30) / 10.0;
        humidity = 55.0 + random(-20, 20);
      }
      int16_t uplink = transportGetSignalReport(SR_UPLINK_QUALITY);
      int16_t power_link = transportGetSignalReport(SR_TX_POWER_LEVEL);
      int16_t tx_power_percent = transportGetSignalReport(SR_TX_POWER_PERCENT);
      int16_t tx_rssi = transportGetSignalReport(SR_TX_RSSI);
      int16_t rx_rssi = transportGetSignalReport(SR_RX_RSSI);
      int16_t tx_snr = transportGetSignalReport(SR_TX_SNR);
      int16_t rx_snr = transportGetSignalReport(SR_RX_SNR);
    
      send(msgUplinkQuality.set(uplink));
      send(msgTxLevel.set(power_link));
      send(msgTxPercent.set(tx_power_percent));
      // retrieve RSSI / SNR reports from incoming ACK
      send(msgTxRSSI.set(tx_rssi));
      send(msgRxRSSI.set(rx_rssi));
      send(msgTxSNR.set(tx_snr));
      send(msgRxSNR.set(rx_snr));
      // wait a bit
    
      showDisplay(temperature, humidity, counter, uplink, power_link, tx_power_percent, tx_rssi, rx_rssi);
      send(msgTemp.set(temperature, 2));
      send(msgHum.set(humidity, 2));
      wait(5000);
    
      if (switch_led == 1)
      {
        digitalWrite(ledPin, HIGH);
        switch_led = 0;
      } else {
        digitalWrite(ledPin, LOW);
        switch_led = 1;
      }
    
    }
    
    const char temp[] = "Vattentemp:";
    const char hum[] = "Hum: ";
    const char counter_text[] = "Counter: ";
    const char hello[] = "Hello";
    const char clearText[] = "CLEAR";
    const char UPLINK_QUALITYtext[] = "Uplink_qa: ";
    const char TX_POWER_LEVELtext[] = "Tx power level: ";
    const char TX_RSSItext[] = "Tx rssi: ";
    const char RX_RSSItext[] = "RX rssi";
    const char TX_POWER_PERCENT_text[] = "Tx power:";
    
    
    void clearScreen()
    {
      display.setFullWindow();
      display.setTextColor(GxEPD_BLACK);
      display.fillScreen(GxEPD_WHITE);
      display.setCursor(0, 0);
      display.firstPage();
      do
      {
      }
      while (display.nextPage() );
    }
    
    void showDisplay(float temperature, int humidity, int counter,
                    int UPLINK_QUALITY, int TX_POWER_LEVEL, int TX_POWER_PERCENT,
                    int TX_RSSI, int RX_RSSI)
    {
      display.setRotation(1);
      display.setPartialWindow(0, 0, display.width(), display.height());
      display.setTextColor(GxEPD_BLACK);
      //display.setFullWindow();
      display.setCursor(0, 0);
      display.firstPage();
      // display.fillScreen(GxEPD_WHITE);
      uint16_t x = (display.width() ) ;
      uint16_t y = (display.height() ) ;
      display.setCursor(10, 50);
    
      do
      {
        display.setFont(&FreeSans18pt7b);
        display.println(temp);
        display.setFont(&FreeMonoBold9pt7b);
        display.println();
        display.println();
        display.setFont(&FreeSansBold24pt7b);
        display.print(temperature, 1);
        display.setFont(&FreeMonoBold9pt7b);
        display.println();
    
        display.print(counter_text);
        display.println(counter);
    
    
        display.print(TX_RSSItext);
        display.println(TX_RSSI);
    
        display.print(RX_RSSItext);
        display.println(RX_RSSI);
      }
      while (display.nextPage() );
      Serial.println("showDisplay done");
    }
    
    

    Gateway code:

    /*
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2019 Sensnology AB
     * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - tekka
     *
     * DESCRIPTION
     * The ESP32 gateway sends data received from sensors to the WiFi link.
     * The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
     *
     * Make sure to fill in your ssid and WiFi password below.
     */
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    #define MY_DEBUG_VERBOSE_RFM95
    #define MY_DEBUG_VERBOSE_TRANSPORT
    #define MY_DEBUG_VERBOSE_GATEWAY
    #define MY_DEBUG_VERBOSE_TRANSPORT_HAL
    
    #define MY_RADIO_RFM95
    
    #define RST     14   // GPIO14 -- SX1278's RESET
    #define DI0     26   // GPIO26 -- SX1278's IRQ(Interrupt Request)
    
    #define MY_RFM95_IRQ_PIN DI0
    #define MY_RFM95_IRQ_NUM MY_RFM95_IRQ_PIN
    #define MY_RFM95_CS_PIN SS
    
    #define MY_RFM95_FREQUENCY (RFM95_434MHZ)
    
    #define MY_GATEWAY_ESP32
    #define MY_GATEWAY_MQTT_CLIENT
    
    // Set this node's subscribe and publish topic prefix
    #define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway1-out"
    #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway1-in"
    
    // Set MQTT client id
    #define MY_MQTT_CLIENT_ID "mysensors-1"
    
    // Set WIFI SSID and password
    #define MY_WIFI_SSID "xxxxx"
    #define MY_WIFI_PASSWORD "xxxx"
    
    // Set the hostname for the WiFi Client. This is the hostname
    // passed to the DHCP server if not static.
    #define MY_HOSTNAME "ESP32_MQTT_GW"
    
    // MQTT broker ip address.
    #define MY_CONTROLLER_IP_ADDRESS 10, 0, 0, 3
    
    // The MQTT broker port to to open
    #define MY_PORT 1883
    
    #include <MySensors.h>
    
    void setup()
    {
    	Serial.println("Setup");
    }
    
    void presentation()
    {
    	// Present locally attached sensors here
    }
    
    void loop()
    {
    	// Send locally attech sensors data here
    }
    
    

    Debug log from sensor:

    23 MCO:BGN:INIT NODE,CP=RLNNN---,FQ=16,REL=255,VER=2.3.2
    29 TSM:INIT
    30 TSF:WUR:MS=0
    31 RFM95:INIT
    38 RFM95:INIT:PIN,CS=11,IQP=16,IQN=16,RST=15
    52 RFM95:PTX:LEVEL=13
    54 TSM:INIT:TSP OK
    55 TSM:INIT:STATID=140
    58 TSF:SID:OK,ID=140
    60 TSM:FPAR
    61 RFM95:SWR:SEND,TO=255,SEQ=0,RETRY=0
    7064 ?TSF:MSG:SEND,140-140-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=NACK:
    13071 !TSM:FPAR:NO REPLY
    13073 TSM:FPAR
    13074 RFM95:SWR:SEND,TO=255,SEQ=1,RETRY=0
    20078 ?TSF:MSG:SEND,140-140-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=1,st=NACK:
    26085 !TSM:FPAR:NO REPLY
    26087 TSM:FPAR
    26088 RFM95:SWR:SEND,TO=255,SEQ=2,RETRY=0
    33092 ?TSF:MSG:SEND,140-140-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=2,st=NACK:
    39099 !TSM:FPAR:NO REPLY
    39101 TSM:FPAR
    

    Debug from gateway:

    
    1982032 THA:DATA:AVAIL
    1982084 RFM95:SAC:SEND ACK,TO=10,SEQ=27,RSSI=-17,SNR=9
    1982132 THA:RCV:MSG=0A0A0022810D0500FFFFFF
    1982136 THA:RCV:MSG LEN=11
    1982138 TSF:MSG:READ,10-10-0,s=5,c=1,t=13,pt=4,l=4,sg=0:-256
    1982143 GWT:TPS:TOPIC=mygateway1-out/10/5/1/0/13,MSG SENT
    1982782 THA:DATA:AVAIL
    1982834 RFM95:SAC:SEND ACK,TO=10,SEQ=28,RSSI=-17,SNR=10
    1982882 THA:RCV:MSG=0A0A0022810D0609000000
    1982886 THA:RCV:MSG LEN=11
    1982888 TSF:MSG:READ,10-10-0,s=6,c=1,t=13,pt=4,l=4,sg=0:9
    1982893 GWT:TPS:TOPIC=mygateway1-out/10/6/1/0/13,MSG SENT
    1983582 THA:DATA:AVAIL
    1983634 RFM95:SAC:SEND ACK,TO=10,SEQ=29,RSSI=-18,SNR=9
    1983682 THA:RCV:MSG=0A0A002AE100086666CE4102
    1983686 THA:RCV:MSG LEN=12
    1983688 TSF:MSG:READ,10-10-0,s=8,c=1,t=0,pt=7,l=5,sg=0:25.80
    1983694 GWT:TPS:TOPIC=mygateway1-out/10/8/1/0/0,MSG SENT
    1984382 THA:DATA:AVAIL
    1984434 RFM95:SAC:SEND ACK,TO=10,SEQ=30,RSSI=-18,SNR=9
    1984482 THA:RCV:MSG=0A0A002AE101070000544202
    1984486 THA:RCV:MSG LEN=12
    1984488 TSF:MSG:READ,10-10-0,s=7,c=1,t=1,pt=7,l=5,sg=0:53.00
    1984494 GWT:TPS:TOPIC=mygateway1-out/10/7/1/0/1,MSG SENT
    1988912 THA:DATA:AVAIL
    1988914 THA:RCV:MSG=8C8CFF020307FF
    1988917 THA:RCV:MSG LEN=7
    1988919 TSF:MSG:READ,140-140-255,s=255,c=3,t=7,pt=0,l=0,sg=0:
    1988924 TSF:MSG:BC
    1988926 TSF:MSG:FPAR REQ,ID=140
    1988929 TSF:PNG:SEND,TO=0
    1988931 TSF:CKU:OK
    1988933 TSF:MSG:GWL OK
    1989262 THA:SND:MSG=00008C0A2308FF00
    1989265 RFM95:SWR:SEND,TO=140,SEQ=65,RETRY=0
    1989817 !RFM95:SWR:NACK
    1989836 RFM95:SWR:SEND,TO=140,SEQ=66,RETRY=1
    1990388 !RFM95:SWR:NACK
    1990478 RFM95:SWR:SEND,TO=140,SEQ=66,RETRY=2
    1991030 !RFM95:SWR:NACK
    1991062 RFM95:SWR:SEND,TO=140,SEQ=66,RETRY=3
    1991614 !RFM95:SWR:NACK
    1991630 RFM95:SWR:SEND,TO=140,SEQ=66,RETRY=4
    1992182 !RFM95:SWR:NACK
    1992266 THA:SND:MSG LEN=8,RES=0
    1992268 !TSF:MSG:SEND,0-0-140-140,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=NACK:0
    

    And here I can see that the gateway recieves data from sensor 140 but can't ack :(

    Can someone please help me?

    Troubleshooting

  • GWT:TPC:CONNECTING
    S smilvert

    @electrik A ticket is raised quite long time ago, https://github.com/mysensors/MySensors/issues/1376

    Troubleshooting

  • GWT:TPC:CONNECTING
    S smilvert

    No I have no idea. For me it seems to work.

    Currently I don't have any sensors conncted so its hard to see if it works.

    Troubleshooting

  • GWT:TPC:CONNECTING
    S smilvert

    @DenisJ I have the same problem. Works with

    #define MY_GATEWAY_ESP32
    

    but with

    #define MY_GATEWAY_ESP32
    #define MY_GATEWAY_MQTT_CLIENT
    

    it dosen't. But when I changed the delay to 3000

    bool gatewayTransportConnect(void)
    {
    #if defined(MY_GATEWAY_ESP8266) || defined(MY_GATEWAY_ESP32)
    	if (WiFi.status() != WL_CONNECTED) {
    		GATEWAY_DEBUG(PSTR("GWT:TPC:CONNECTING...\n"));
    		delay(3000); // Was 1000
    		return false;
    	}
    	GATEWAY_DEBUG(PSTR("GWT:TPC:IP=%s\n"), WiFi.localIP().toString().c_str());
    

    in MyGatewayTransportMQTTClient.cpp then it started to work! :)

    Troubleshooting

  • Heltec esp32 LoRa oled
    S smilvert

    @mrussi I am also interested in using an esp32 with lora as the gateway. Did you make it work?

    I planning to buy, https://www.botnroll.com/en/esp/2979-esp32-wifi-bluetooth-lora-sx1278-433mhz-with-0-96-oled-display.html

    Hardware

  • NRF52 -> Will not wake after sleep
    S smilvert

    I have been trying @nagelc code with a lot of debug prints and I think that my device is stuck after

    MyHwNRF5.cpp

    inline void hwSleep(void)
    {	CORE_DEBUG(PSTR("In hwSleep, 345\n"));
    	__WFE();
    	__SEV();
    	__WFE();
    	CORE_DEBUG(PSTR("In hwSleep, 351\n"));
    }
    
    int8_t hwSleep(uint32_t ms)
    {
    	hwSleepPrepare(ms);
    	while (nrf5_rtc_event_triggered == false) {
    		hwSleep();
    	}
    	CORE_DEBUG(PSTR("In hwSleep, 357\n"));
    	hwSleepEnd(ms);
    	return MY_WAKE_UP_BY_TIMER;
    }
    

    And I will not go to hwSleepEnd

    11274 MCO:SLP:MS=5000,SMS=0,I1=255,M1=255,I2=255,M2=255
    11280 TSF:TDI:TPD
    11281 After transport Disable
    11284 Before hwSleep
    11286 In hwSleepPrepare, 287
    11289 In hwSleepPrepare,300
    11291 In hwSleep, 345
    
    Troubleshooting

  • NRF52 -> Will not wake after sleep
    S smilvert

    @nagelc Thanks will try

    Troubleshooting

  • NRF52 -> Will not wake after sleep
    S smilvert

    @nagelc can you use
    MY_DEBUG_VERBOSE_NRF5_ESB

    Do I need to add a bigger capacitor between gnd and +3?

    Troubleshooting

  • NRF52 -> Will not wake after sleep
    S smilvert

    I have a feeling that the

    Wait()
    

    Is the problem but haven't had time to investigate.

    Troubleshooting

  • NRF52 -> Will not wake after sleep
    S smilvert

    Hi

    Finally I have had time to solder my project, Temp_hum, and started to create the code for it. But I struggle with some bascis

    Code for the sensor:

    
    #define MY_NODE_ID 37
    
    // Enable debug prints
    #define MY_DEBUG
    
    // #define MY_DEBUG_VERBOSE_NRF5_ESB
    #define MY_BAUD_RATE 115200
    
    // Enable and select radio type attached
    //#define MY_RADIO_RF24
    //#define MY_RADIO_RFM69
    //#define MY_RS485
    #define MY_RADIO_NRF5_ESB
    
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define CHILD_ID_VOLT 2
    
    #define IS_NRF52
    // #define IS_NRF51
    
    #define SHORT_WAIT 100
    
    // Sleep time between sensor updates (in milliseconds)
    static const uint64_t UPDATE_INTERVAL = 6000;
    
    static bool metric = true;
    
    float batteryPcnt;
    float oldBatteryPcnt;
    
    #include <MySensors.h>
    #include <SI7021.h>
    
    static SI7021 sensor;
    
    void disableNfc()
    { //only applied to nRF52
    
    #ifdef IS_NRF52
      //Make pins 9 and 10 usable as GPIO pins.
      NRF_NFCT->TASKS_DISABLE = 1; //disable NFC
      NRF_NVMC->CONFIG = 1;        // Write enable the UICR
      NRF_UICR->NFCPINS = 0;       //Make pins 9 and 10 usable as GPIO pins.
      NRF_NVMC->CONFIG = 0;        // Put the UICR back into read-only mode.
    #endif
    }
    
    void turnOffRadio()
    {
      NRF_RADIO->TASKS_DISABLE = 1;
      while (!(NRF_RADIO->EVENTS_DISABLED))
      {
      } //until radio is confirmed disabled
    }
    
    void turnOffAdc()
    {
    #ifndef IS_NRF52
      if (NRF_SAADC->ENABLE)
      { //if enabled, then disable the SAADC
        NRF_SAADC->TASKS_STOP = 1;
        while (NRF_SAADC->EVENTS_STOPPED)
        {
        }                      //wait until stopping of SAADC is confirmed
        NRF_SAADC->ENABLE = 0; //disable the SAADC
        while (NRF_SAADC->ENABLE)
        {
        } //wait until the disable is confirmed
      }
    #endif
    }
    
    void turnOffUarte0()
    {
    #ifndef IS_NRF52
      NRF_UARTE0->TASKS_STOPRX = 1;
      NRF_UARTE0->TASKS_STOPTX = 1;
      NRF_UARTE0->TASKS_SUSPEND = 1;
      NRF_UARTE0->ENABLE = 0; //disable UART0
      while (NRF_UARTE0->ENABLE != 0)
      {
      }; //wait until UART0 is confirmed disabled.
    #endif
    
    #ifdef IS_NRF51
      NRF_UART0->TASKS_STOPRX = 1;
      NRF_UART0->TASKS_STOPTX = 1;
      NRF_UART0->TASKS_SUSPEND = 1;
      NRF_UART0->ENABLE = 0; //disable UART0
      while (NRF_UART0->ENABLE != 0)
      {
      }; //wait until UART0 is confirmed disabled.
    #endif
    }
    
    void turnOffHighFrequencyClock()
    {
      NRF_CLOCK->TASKS_HFCLKSTOP = 1;
      while ((NRF_CLOCK->HFCLKSTAT) & 0x0100)
      {
      } //wait as long as HF clock is still running.
    }
    
    void mySleepPrepare()
    { //turn-off energy drains prior to sleep
      turnOffHighFrequencyClock();
      turnOffRadio();
      //turnOffUarte0();
    }
    
    void presentation()
    {
      Serial.println("Presentation");
      // Send the sketch info to the gateway
      sendSketchInfo("TemperatureAndHumidity", "1.2");
    
      // Present sensors as children to gateway
      present(CHILD_ID_HUM, S_HUM, "Humidity");
      delay(SHORT_WAIT);
      present(CHILD_ID_TEMP, S_TEMP, "Temperature");
      delay(SHORT_WAIT);
      present(CHILD_ID_VOLT, S_MULTIMETER, "Battery");
    
      metric = getControllerConfig().isMetric;
      Serial.println("End presention");
    }
    
    void setup()
    {
      Serial.println("Setup");
      hwInit();
      
      disableNfc(); //remove unnecessary energy drains
      turnOffAdc(); //remove unnecessary energy drains
      while (not sensor.begin())
      {
        Serial.println(F("Sensor not detected!"));
        wait(5000);
      }
      Serial.println("End Setup");
    }
    
    void mySleep(uint32_t ms)
    {
      mySleepPrepare();  //Take steps to reduce drains on battery current prior to sleeping
      sleep(ms);
    }
    
    void loop()
    {
      // Read temperature & humidity from sensor.
      const float temperature = float(metric ? sensor.getCelsiusHundredths() : sensor.getFahrenheitHundredths()) / 100.0;
      const float humidity = float(sensor.getHumidityBasisPoints()) / 100.0;
    
    #ifdef MY_DEBUG
      Serial.print(F("Temp "));
      Serial.print(temperature);
      Serial.print(metric ? 'C' : 'F');
      Serial.print(F("\tHum "));
      Serial.println(humidity);
    #endif
    
      static MyMessage msgHum(CHILD_ID_HUM, V_HUM);
      static MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
      static MyMessage msgBattery(CHILD_ID_VOLT, V_VOLTAGE);
    
      send(msgTemp.set(temperature, 2));
    
      wait(SHORT_WAIT);
      send(msgHum.set(humidity, 2));
    
      float batteryVolt = getInternalVoltage();
      batteryPcnt =(batteryVolt / 3.3) * 100;
      if (batteryPcnt > 100)
      {
        batteryPcnt = 100;
      }
    #ifdef MY_DEBUG
      Serial.print(F("Vbat "));
      Serial.print(batteryVolt);
      Serial.print(F(" Battery percent "));
      Serial.println(batteryPcnt);
    #endif
    
      // Battery readout should only go down. So report only when new value is smaller than previous one.
      if (batteryPcnt < oldBatteryPcnt)
      {
    
        wait(SHORT_WAIT);
        send(msgBattery.set(batteryVolt, 3));
        wait(SHORT_WAIT);
        if (batteryPcnt < oldBatteryPcnt)
        {
          sendBatteryLevel(batteryPcnt);
          oldBatteryPcnt = batteryPcnt;
        }
    
        // Sleep until next update to save energy
        // 
        
      }
      //delay(5000);
      mySleep(UPDATE_INTERVAL);
    }
    
    float getInternalVoltage()
    {
      return ((float)hwCPUVoltage()) / 1000.0;
    }
    
    

    Have some problems.

    First and biggest: The sensor will not wake,

    2577 TSF:MSG:SEND,37-37-0-0,s=0,c=1,t=1,pt=7,l=5,sg=0,ft=0,st=OK:33.34
    Vbat 3.29 Battery percent 99.67
    2587 MCO:SLP:MS=6000,SMS=0,I1=255,M1=255,I2=255,M2=255
    2591 TSF:TDI:TPD
    8593 MCO:SLP:WUP=-1
    8595 TSF:TRI:TPU
    Temp 23.46C	Hum 33.85
    8626 TSF:MSG:SEND,37-37-0-0,s=1,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=OK:23.46
    8733 TSF:MSG:SEND,37-37-0-0,s=0,c=1,t=1,pt=7,l=5,sg=0,ft=0,st=OK:33.85
    Vbat 3.29 Battery percent 99.67
    8743 MCO:SLP:MS=6000,SMS=0,I1=255,M1=255,I2=255,M2=255
    8748 TSF:TDI:TPD
    

    (Some times I got stuck at:

    5803 MCO:SLP:MS=6000,SMS=0,I1=255,M1=255,I2=255,M2=255
    5807 TSF:TDI:TPD
    11809 MCO:SLP:WUP=-1
    11811 TSF:TRI:TPU
    Temp 22.69C	Hum 31.08
    11842 TSF:MSG:SEND,37-37-0-0,s=1,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=OK:22.69
    

    )

    Second when im trying to debug with

    #define MY_DEBUG_VERBOSE_NRF5_ESB
    

    the node will not pass presentation.

    153 NRF5:SND:END=1,ACK=1,RTRY=1,RSSI=-55,WAKE=5
    4158 TSF:MSG:SEND,37-37-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.3.2
    4164 NRF5:SND:TO=0,LEN=8,PID=1,NOACK=0
    4169 NRF5:SND:END=1,ACK=1,RTRY=1,RSSI=-55,WAKE=4
    4174 TSF:MSG:SEND,37-37-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
    4180 NRF5:RX:LEN=9,NOACK=0,PID=2,RSSI=-74,RX=0
    4184 TSF:MSG:READ,0-0-37,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
    4190 NRF5:RX:LEN=8,NOACK=0,PID=1,RSSI=-53,RX=0
    4194 TSF:MSG:READ,0-0-37,s=255,c=3,t=6,pt=0,l=1,sg=0:M
    Presentation
    4200 NRF5:SND:TO=0,LEN=29,PID=2,NOACK=0
    4206 NRF5:SND:END=1,ACK=1,RTRY=1,RSSI=-55,WAKE=5
    4210 TSF:MSG:SEND,37-37-0-0,s=255,c=3,t=11,pt=0,l=22,sg=0,ft=0,st=OK:TemperatureAndHumidity
    4218 NRF5:SND:TO=0,LEN=10,PID=3,NOACK=0
    4223 NRF5:SND:END=1,ACK=1,RTRY=1,RSSI=-55,WAKE=4
    4228 TSF:MSG:SEND,37-37-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.2
    4234 NRF5:SND:TO=0,LEN=15,PID=0,NOACK=0
    4239 NRF5:SND:END=1,ACK=1,RTRY=1,RSSI=-55,WAKE=4
    4244 TSF:MSG:SEND,37-37-0-0,s=0,c=0,t=7,pt=0,l=8,sg=0,ft=0,st=OK:Humidity
    

    Someone that can help me?

    Troubleshooting

  • hwSPI NRF52
    S smilvert

    Hi

    I want to understand how the hwSPI works for the NRF52 and a RFM95 module.

    I suppose that I can define more then one SPI interface in the file MyBoardNRF5.h so it looks like
    SodaqMoja/SodaqCore-samd (should be updated to the NRF52 pins)

    #ifdef ENABLE_SPI1
    #define SPI_INTERFACES_COUNT 2
    #else
    #define SPI_INTERFACES_COUNT 1
    #endif
    
    // SPI
    #define PIN_SPI_MISO         (42u)
    #define PIN_SPI_SS           (43u)
    #define PIN_SPI_MOSI         (44u)
    #define PIN_SPI_SCK          (45u)
    
    static const uint8_t MISO = PIN_SPI_MISO;
    static const uint8_t SS   = PIN_SPI_SS ;
    static const uint8_t SS_DFLASH  = PIN_SPI_SS ;
    static const uint8_t MOSI = PIN_SPI_MOSI ;
    static const uint8_t SCK  = PIN_SPI_SCK ;
    
    // SPI1
    #define PIN_SPI1_MISO        (53u)
    #define PIN_SPI1_SS          (54u)
    #define PIN_SPI1_MOSI        (55u)
    #define PIN_SPI1_SCK         (56u)
    
    static const uint8_t MISO1 = PIN_SPI1_MISO;
    static const uint8_t SS1   = PIN_SPI1_SS;
    static const uint8_t MOSI1 = PIN_SPI1_MOSI;
    static const uint8_t SCK1  = PIN_SPI1_SCK;
    

    But I don't get how I will init the second SPI bus and point it to the RFM95 module. Guessing it should be define RFM95_SPI SPI1 or something like that?

    #if !defined(RFM95_SPI)
    #define RFM95_SPI hwSPI //!< default SPI
    #endif
    
    Development

  • nRF5 action!
    S smilvert

    @omemanti Well it seems to start working now... Hopefully it works :) Havn't restart the gateway in 2 weeks now

    My Project

  • nRF5 action!
    S smilvert

    I have recently installed an Ebyte E73 as my gateway with a DHT22. The problem is that I need to restart the gateway every 2 days and I can't figure out why. Can someone help me?

    /**
       The MySensors Arduino library handles the wireless radio link and protocol
       between your home built sensors/actuators and HA controller of choice.
       The sensors forms a self healing radio network with optional repeaters. Each
       repeater and gateway builds a routing tables in EEPROM which keeps track of the
       network topology allowing messages to be routed to nodes.
    
       Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
       Copyright (C) 2013-2017 Sensnology AB
       Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
    
       Documentation: http://www.mysensors.org
       Support Forum: http://forum.mysensors.org
    
       This program is free software; you can redistribute it and/or
       modify it under the terms of the GNU General Public License
       version 2 as published by the Free Software Foundation.
    
     *******************************
    
       REVISION HISTORY
    
    
    */
    
    // Enable debug prints
    #define MY_DEBUG
    
    // Enable serial gateway
    #define MY_GATEWAY_SERIAL
    
    
    
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Enable and select radio type attached
    //#define MY_RADIO_NRF24
    #define MY_RADIO_NRF5_ESB
    //#define MY_RADIO_RFM69
    //#define MY_RADIO_RFM95
    
    #include <SPI.h>
    #include <MySensors.h>
    #include "DHT.h"
    
    int switch_led = 1;
    #define ledPin 11
    // Set this to the pin you connected the DHT's data pin to
    #define DHT_DATA_PIN 02
    #define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
    
    
    // Set this offset if the sensor has a permanent small offset to the real temperatures.
    // In Celsius degrees (as measured by the device)
    #define SENSOR_TEMP_OFFSET 0
    
    // Sleep time between sensor updates (in milliseconds)
    // Must be >1000ms for DHT22 and >2000ms for DHT11
    static const uint64_t UPDATE_INTERVAL = 600000;
    
    // Force sending an update of the temperature after n sensor reads, so a controller showing the
    // timestamp of the last update doesn't show something like 3 hours in the unlikely case, that
    // the value didn't change since;
    // i.e. the sensor would force sending an update every UPDATE_INTERVAL*FORCE_UPDATE_N_READS [ms]
    static const uint8_t FORCE_UPDATE_N_READS = 10;
    
    #define CHILD_ID_HUM 1
    #define CHILD_ID_TEMP 0
    
    float lastTemp;
    float lastHum;
    uint8_t nNoUpdatesTemp;
    uint8_t nNoUpdatesHum;
    bool metric = true;
    
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    DHT dht(DHT_DATA_PIN, DHTTYPE);
    
    void setup()
    {
        hwPinMode(LED_BUILTIN,OUTPUT_D0H1);
    
        NRF_CLOCK->INTENSET=B11;  //enable interrupts for EVENTS_HFCLKSTARTED and  EVENTS_LFCLKSTARTED
        NRF_CLOCK->TASKS_HFCLKSTART=1;  //start the high frequency crystal oscillator clock
        while (!(NRF_CLOCK->EVENTS_HFCLKSTARTED)) {} //wait until high frequency crystal oscillator clock is up to speed and working
    
        pinMode(PIN_LED1, OUTPUT);
        digitalWrite(PIN_LED1, HIGH);
    
        dht.begin(); // set data pin of DHT sensor
    }
    
    void presentation()
    {
        // Send the sketch version information to the gateway and controller
        sendSketchInfo("Serial Gateway nrf52", "1.0");
        wait(500);
        // Register all sensors to gw (they will be created as child devices)
        present(CHILD_ID_TEMP, S_TEMP);
        present(CHILD_ID_HUM, S_HUM);
    }
    
    void loop()
    {
    
        // Reading temperature or humidity takes about 250 milliseconds!
        // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
        float h = dht.readHumidity();
        // Read temperature as Celsius (the default)
        float t = dht.readTemperature();
        // Read temperature as Fahrenheit (isFahrenheit = true)
        float f = dht.readTemperature(true);
        Serial.print("Test print");
        // Check if any reads failed and exit early (to try again).
        if (isnan(h) || isnan(t) || isnan(f)) {
        //Serial.println("Failed to read from DHT sensor!");
        return;
        } else {
        send(msgHum.set(h, 1));
        send(msgTemp.set(t, 1));
    
        }
    
        wait(UPDATE_INTERVAL);
    }
    
    
    My Project

  • my first nrf5 ... NRF51/NRF52 which is better for MySensors ?
    S smilvert

    I have been able to use platformio for my project quite recently and still have some problems that I haven't had time to solve yet.

    My platformio.ini for a NRF51832

    [env:nrf51_dk]
    platform = nordicnrf51
    framework = arduino
    board = rfduino
    upload_protocol = stlink
    board_build.f_cpu = 16000000L
    build_flags = -DNRF51 -DMYBOARDNRF5 -I{build.path}
    

    the only problem for my is that the flags

    -DMYBOARDNRF5 -I{build.path}
    

    dosen't work so the mynrf5board.h/c isn't read => I need to update the
    vim ~/.platformio/packages/framework-arduinonordicnrf5/variants/Generic/variant.h myself.

    Hardware

  • nRF5 action!
    S smilvert

    @neverdie Sorry, im a bit confused.

    If im are going to use the BT832 for a battery sensor do I need to connet a 32 khz crystal like you did on the 10+ years wireless PIR Sensor (on just one set of 3 AA's!) project? But you have also written:
    @neverdie said in nRF5 action!:

    @alowhum IIRC, the crystal oscillator is only required by Bluetooth. For everything else, the internal resonator is sufficient.

    How much more current are used if the crystal is not connected?

    Can I use P00/P01 as a data pin instead of using the crystal?

    My Project

  • nRF5 action!
    S smilvert

    @neverdie Im guessing that the BT832 dosen't have the 32.768 khz crystal but the inductors?

    The datasheet says

    Standby current consumption is important for battery-powered product. We suggest adding a 32.768 kHz crystal 
    and 2 capacitors as shown in the upper left corner of the evaluation board schematics. The 32MHz main clock 
    won’t be active at idle state to save power.
    
    Two inductors required for DCDC converter are inside BT832 module. You can enable DCDC to lower
    power consumption.
    
    My Project

  • nRF5 action!
    S smilvert

    @NeverDie How do I know which nRF52832 board I should use?

    Does the CFsunbird-nRF52832 has the DC/DC inductors?
    Or can I use nRF51822?

    Want a cheap chip, easy to solder (Have a couple of Ebyte e-73 but they take some time to solder :( and if I understand correctly, the DC / DC inductors are missing?)

    My Project

  • nRF5 action!
    S smilvert

    @monte But you solve your issue with the WT15822 board? Can you please share your sketch?

    Is the range good of the WT15822 board?

    I have started sketching to create a couple of new simple temp / hum sensors (WT15822, si7021 and cr2032) and want to know if I can use WT15822 before I order a pcb :)

    My Project

  • GUIDE - NRF5 / NRF51 / NRF52 for beginners
    S smilvert

    Hi.

    I have read https://devzone.nordicsemi.com/b/blog/posts/measuring-lithium-battery-voltage-with-nrf51 but which pin is VBG? p0.01 = adc?

    Need to recalclulate the resistance for 2 aaa batteries.

    @alowhum Can you clearify how to read MyBoardNRF5.h? Is PIN_AIN0 = p0.00?

    What is the benift to use hwPinMode instead of using pinMode()?

    Development
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular