Vilém Kužel
Published © GPL3+

IoT for Bees (& Beekeepers a Bit Too)

A device which allows beekeepers to remotely monitor their beehives and send an alert in case of theft.

BeginnerShowcase (no instructions)16 hours940

Things used in this project

Hardware components

Rapid IoT Prototyping Kit
NXP Rapid IoT Prototyping Kit
×1
MIKROE Hexiwear docking station
×1
MIKROE SigFox click (Europe)
×1

Software apps and online services

NXP Rapid IoT Studio

Story

Read more

Schematics

nxp-beehive-monitor-1_JypQn8i2Jy.jpg

NXP Studio Project

This is how the concept looks like in NXP Online Studio IDE

Code

Rapid IoT Beehive Monitor.atmo

Plain text
Project for https://rapid-iot-studio.nxp.com
{
  "name": "Rapid IoT Beehive Monitor",
  "createVersion": "2017-08-12",
  "description": "",
  "lastModified": "2018-02-13T00:39:19.386Z",
  "created": "2018-02-13T00:39:19.386Z",
  "meta": {
    "projectTypeName": "NXP Rapid IoT",
    "projectTypeId": "NxpRpk"
  },
  "planes": {
    "NXP Rapid IoT": {
      "type": "mcuxpresso",
      "compilerVersion": "latest",
      "variants": [
        "NxpRpk"
      ],
      "meta": {},
      "elements": [
        {
          "name": "FXOS8700AccelerometerMagnetometer",
          "type": "EmbeddedFXOS8700",
          "variants": [
            "embedded",
            "triggers",
            "abilities",
            "properties",
            "variables"
          ],
          "properties": {
            "errorData": {},
            "code": {
              "trigger": "\tATMO_CreateValueBool(out, true);\n\treturn ATMO_Status_Success;",
              "setup": "\tATMO_FXOS8700_Config_t config;\n\tconfig.address = ATMO_PROPERTY(FXOS8700AccelerometerMagnetometer, i2cAddress);\n\tconfig.i2cDriverInstance = ATMO_PROPERTY(FXOS8700AccelerometerMagnetometer, i2cInstance);\n\tconfig.gpioDriverInstance = ATMO_PROPERTY(FXOS8700AccelerometerMagnetometer, gpioInstance);\n\tconfig.int1En = ATMO_PROPERTY(FXOS8700AccelerometerMagnetometer, interrupt1Enabled);\n    config.int2En = ATMO_PROPERTY(FXOS8700AccelerometerMagnetometer, interrupt2Enabled);\n    config.int1Pin = ATMO_PROPERTY(FXOS8700AccelerometerMagnetometer, interrupt1Gpio);\n    config.int2Pin = ATMO_PROPERTY(FXOS8700AccelerometerMagnetometer, interrupt2Gpio);\n\n    switch(ATMO_PROPERTY(FXOS8700AccelerometerMagnetometer, motionDetectType))\n    {\n        case FXOS8700_NoDetect:\n        {\n            config.freefallEnabled = false;\n            config.motionEnabled = false;\n            config.tapDetectionEnabled = false;\n            break;\n        }\n        case FXOS8700_FreefallDetect:\n        {\n            config.freefallEnabled = true;\n            config.motionEnabled = false;\n            config.tapDetectionEnabled = false;\n            break;\n        }\n        case FXOS8700_MotionDetect:\n        {\n            config.freefallEnabled = false;\n            config.motionEnabled = true;\n            config.tapDetectionEnabled = false;\n            break;\n        }\n        case FXOS8700_TapDetect:\n        {\n            config.freefallEnabled = false;\n            config.motionEnabled = false;\n            config.tapDetectionEnabled = true;\n            break; \n        }\n        default:\n        {\n            config.freefallEnabled = false;\n            config.motionEnabled = false;  \n            config.tapDetectionEnabled = false;\n            break;\n        }\n    }\n\n    ATMO_FXOS8700_SetMotionDetectedAbilityHandle(ATMO_ABILITY(FXOS8700AccelerometerMagnetometer, detectMotion));\n    ATMO_FXOS8700_SetFreefallDetectedAbilityHandle(ATMO_ABILITY(FXOS8700AccelerometerMagnetometer, detectFreefall));\n    ATMO_FXOS8700_SetTapDetectedAbilityHandle(ATMO_ABILITY(FXOS8700AccelerometerMagnetometer, detectTap));\n\tATMO_FXOS8700_Init(&config);\n\n    return ATMO_Status_Success;\n\t",
              "setEnabled": "ATMO_FXOS8700_SetEnabled(true);\nreturn ATMO_Status_Success;",
              "setDisabled": "ATMO_FXOS8700_SetEnabled(false);\nreturn ATMO_Status_Success;",
              "setEnabledDisabled": "bool enabled = false;\nATMO_GetBool(in, &enabled);\nATMO_FXOS8700_SetEnabled(enabled);\nreturn ATMO_Status_Success;",
              "getAccelData": "    ATMO_3dFloatVector_t data;\r\n\r\n    if( ATMO_FXOS8700_GetAccelData(&data) != ATMO_FXOS8700_Status_Success )\r\n    {\r\n        ATMO_CreateValueVoid(out);\r\n        return ATMO_Status_Fail;\r\n    }\r\n\r\n    ATMO_CreateValue3dVectorFloat(out, &data);\r\n\r\n    return ATMO_Status_Success;",
              "getAccelX": "\tATMO_3dFloatVector_t data;\n\n\tif(ATMO_FXOS8700_GetAccelData(&data) != ATMO_FXOS8700_Status_Success)\n\t{\n\t\tATMO_CreateValueVoid(out);\n\t\treturn ATMO_Status_Fail;\n\t}\n\n\tATMO_CreateValueFloat(out, data.x);\n\treturn ATMO_Status_Success;\n",
              "getAccelY": "\tATMO_3dFloatVector_t data;\n\n\tif(ATMO_FXOS8700_GetAccelData(&data) != ATMO_FXOS8700_Status_Success)\n\t{\n\t\tATMO_CreateValueVoid(out);\n\t\treturn ATMO_Status_Fail;\n\t}\n\n\tATMO_CreateValueFloat(out, data.y);\n\treturn ATMO_Status_Success;\n",
              "getAccelZ": "\tATMO_3dFloatVector_t data;\n\n\tif(ATMO_FXOS8700_GetAccelData(&data) != ATMO_FXOS8700_Status_Success)\n\t{\n\t\tATMO_CreateValueVoid(out);\n\t\treturn ATMO_Status_Fail;\n\t}\n\n\tATMO_CreateValueFloat(out, data.z);\n\treturn ATMO_Status_Success;\n",
              "getMagData": "    ATMO_3dFloatVector_t data;\r\n\r\n    if( ATMO_FXOS8700_GetMagData(&data) != ATMO_FXOS8700_Status_Success )\r\n    {\r\n        ATMO_CreateValueVoid(out);\r\n        return ATMO_Status_Fail;\r\n    }\r\n\r\n    ATMO_CreateValue3dVectorFloat(out, &data);\r\n\r\n    return ATMO_Status_Success;",
              "getMagX": "\tATMO_3dFloatVector_t data;\n\n\tif(ATMO_FXOS8700_GetMagData(&data) != ATMO_FXOS8700_Status_Success)\n\t{\n\t\tATMO_CreateValueVoid(out);\n\t\treturn ATMO_Status_Fail;\n\t}\n\n\tATMO_CreateValueFloat(out, data.x);\n\treturn ATMO_Status_Success;\n",
              "getMagY": "\tATMO_3dFloatVector_t data;\n\n\tif(ATMO_FXOS8700_GetMagData(&data) != ATMO_FXOS8700_Status_Success)\n\t{\n\t\tATMO_CreateValueVoid(out);\n\t\treturn ATMO_Status_Fail;\n\t}\n\n\tATMO_CreateValueFloat(out, data.y);\n\treturn ATMO_Status_Success;\n",
              "getMagZ": "\tATMO_3dFloatVector_t data;\n\n\tif(ATMO_FXOS8700_GetMagData(&data) != ATMO_FXOS8700_Status_Success)\n\t{\n\t\tATMO_CreateValueVoid(out);\n\t\treturn ATMO_Status_Fail;\n\t}\n\n\tATMO_CreateValueFloat(out, data.z);\n\treturn ATMO_Status_Success;\n",
              "detectTap": "\treturn ATMO_Status_Success;\n",
              "detectMotion": "\treturn ATMO_Status_Success;\n",
              "detectFreefall": "\treturn ATMO_Status_Success;\n",
              "enableFreefallDetection": "if(ATMO_FXOS8700_EnableFreefallDetection() == ATMO_FXOS8700_Status_Success)\n{\n    return ATMO_Status_Success;\n}\n\nreturn ATMO_Status_Fail;",
              "enableMotionDetection": "if(ATMO_FXOS8700_EnableMotionDetection() == ATMO_FXOS8700_Status_Success)\n{\n    return ATMO_Status_Success;\n}\n\nreturn ATMO_Status_Fail;",
              "enableTapDetection": "if(ATMO_FXOS8700_EnableTapDetection() == ATMO_FXOS8700_Status_Success)\n{\n    return ATMO_Status_Success;\n}\n\nreturn ATMO_Status_Fail;",
              "disableDetection": "if(ATMO_FXOS8700_DisableAllDetection() == ATMO_FXOS8700_Status_Success)\n{\n    return ATMO_Status_Success;\n}\n\nreturn ATMO_Status_Fail;"
            },
            "variables": {},
            "embeddedPropertyConversions": {},
            "codeUserChanged": {
              "setup": false,
              "setEnabled": false,
              "setDisabled": false,
              "setEnabledDisabled": false,
              "getAccelData": false,
              "getAccelX": false,
              "getAccelY": false,
              "getAccelZ": false,
              "getMagData": false,
              "getMagX": false,
              "getMagY": false,
              "getMagZ": false,
              "detectTap": false,
              "detectMotion": false,
              "detectFreefall": false,
              "enableFreefallDetection": false,
              "enableMotionDetection": false,
              "enableTapDetection": false,
              "disableDetection": false,
              "trigger": true
            },
            "i2cInstance": 1,
            "gpioInstance": 0,
            "interrupt1Enabled": false,
            "interrupt2Enabled": true,
            "interrupt1Gpio": "ATMO_DEFAULT_GPIO",
            "interrupt2Gpio": "PTD13",
            "motionDetectType": "FXOS8700_MotionDetect",
            "i2cAddress": "0x1E"
          },
          "meta": {
            "editorX": 71.33349609375,
            "editorY": 42,
            "lastTrigger": "motionDetected"
          },
          "triggers": {
            "triggered": [],
            "accelDataRead": [
              {
                "mapping": {},
                "targetOrder": [],
                "targetElement": "TheftAlertBuzzer",
                "targetAbility": "beep"
              },
              {
                "mapping": {},
                "targetOrder": [],
                "targetElement": "MotionRead",
                "targetAbility": "trigger"
              },
              {
                "mapping": {},
                "targetOrder": [],
                "targetElement": "EmbeddedNxpRpkRgbLed",
                "targetAbility": "toggleRed"
              }
            ],
            "accelXRead": [],
            "accelYRead": [],
            "accelZRead": [],
            "magDataRead": [],
            "magXRead": [],
            "magYRead": [],
            "magZRead": [],
            "tapDetected": [],
            "motionDetected": [
              {
                "mapping": {},
                "targetOrder": [],
                "targetElement": "TheftAlertBuzzer",
                "targetAbility": "beep"
              },
              {
                "mapping": {},
                "targetOrder": [],
                "targetElement": "MotionRead",
                "targetAbility": "trigger"
              },
              {
                "mapping": {},
                "targetOrder": [],
                "targetElement": "EmbeddedNxpRpkRgbLed",
                "targetAbility": "setRedOn"
              },
              {
                "mapping": {},
                "targetOrder": [],
                "targetElement": "TheftAlertBuzzer",
                "targetAbility": "trigger"
              }
            ],
            "freefallDetected": []
          },
          "interruptAbilities": {
            "trigger": false,
            "setup": false,
            "setEnabled": false,
            "setDisabled": false,
            "setEnabledDisabled": false,
            "getAccelData": false,
            "getAccelX": false,
            "getAccelY": false,
            "getAccelZ": false,
            "getMagData": false,
            "getMagX": false,
            "getMagY": false,
            "getMagZ": false,
            "detectTap": false,
            "detectMotion": false,
            "detectFreefall": false,
            "enableFreefallDetection": false,
            "enableMotionDetection": false,
            "enableTapDetection": false,
            "disableDetection": false
          },
          "abilities": [
            {
              "name": "trigger",
              "triggers": [
                "triggered"
              ]
            },
            {
              "name": "setup",
              "triggers": []
            },
            {
              "name": "setEnabled",
              "triggers": []
            },
            {
              "name": "setDisabled",
              "triggers": []
            },
            {
              "name": "setEnabledDisabled",
              "triggers": []
            },
            {
              "name": "getAccelData",
              "triggers": [
                "accelDataRead"
              ]
            },
            {
              "name": "getAccelX",
              "triggers": [
                "accelXRead"
              ]
            },
            {
              "name": "getAccelY",
              "triggers": [
                "accelYRead"
              ]
            },
            {
              "name": "getAccelZ",
              "triggers": [
                "accelZRead"
              ]
            },
            {
              "name": "getMagData",
              "triggers": [
                "magDataRead"
              ]
            },
            {
              "name": "getMagX",
              "triggers": [
                "magXRead"
              ]
            },
            {
              "name": "getMagY",
              "triggers": [
                "magYRead"
              ]
            },
            {
              "name": "getMagZ",
              "triggers": [
                "magZRead"
              ]
            },
            {
              "name": "detectTap",
              "triggers": [
                "tapDetected"
              ]
            },
            {
              "name": "detectMotion",
              "triggers": [
                "motionDetected"
              ]
            },
            {
              "name": "detectFreefall",
              "triggers": [
                "freefallDetected"
              ]
            },
            {
              "name": "enableFreefallDetection",
              "triggers": []
            },
            {
              "name": "enableMotionDetection",
              "triggers": []
            },
            {
              "name": "enableTapDetection",
              "triggers": []
            },
            {
              "name": "disableDetection",
              "triggers": []
            }
          ]
        },
        {
          "name": "TheftAlertBuzzer",
          "type": "EmbeddedNxpRpkBuzzer",
          "variants": [
            "embedded",
            "triggers",
            "abilities",
            "properties",
            "variables",
            "rpk"
          ],
          "properties": {
            "errorData": {},
            "code": {
              "trigger": "\treturn ATMO_Status_Success;",
              "setup": "\n\treturn ATMO_Status_Success;\n    ",
              "beep": "\n    ATMO_MK64F_Buzzer_On();\n    ATMO_PLATFORM_DelayMilliseconds(200);\n    ATMO_MK64F_Buzzer_Off();\n\treturn ATMO_Status_Success;\n    ",
              "turnOn": "\n    ATMO_MK64F_Buzzer_On();\n    ATMO_CreateValueBool(out, true);\n\treturn ATMO_Status_Success;\n    ",
              "turnOff": "\n    ATMO_MK64F_Buzzer_Off();\n    ATMO_CreateValueBool(out, false);\n\treturn ATMO_Status_Success;\n    ",
              "toggle": "\n    bool newState = false;\n    ATMO_MK64F_Buzzer_Toggle(&newState);\n    ATMO_CreateValueBool(out, newState);\n\treturn ATMO_Status_Success;\n    ",
              "setState": "\n    bool on = false;\n    ATMO_GetBool(in, &on);\n\n    if( on )\n    {\n        ATMO_MK64F_Buzzer_On();\n    }\n    else\n    {\n        ATMO_MK64F_Buzzer_Off();\n    }\n    ATMO_CreateValueBool(out, on);\n    \n\treturn ATMO_Status_Success;\n    "
            },
            "variables": {},
            "embeddedPropertyConversions": {},
            "codeUserChanged": {
              "setup": false,
              "beep": false,
              "turnOn": false,
              "turnOff": false,
              "toggle": false,
              "setState": false
            }
          },
          "meta": {
            "editorX": 199.33349609375,
            "editorY": 240,
            "lastTrigger": "triggered"
          },
          "triggers": {
            "triggered": [
              {
                "mapping": {},
                "targetOrder": [],
                "targetElement": "FuncFormatAlert",
                "targetAbility": "trigger"
              }
            ],
            "buzzerStateChange": [
              {
                "mapping": {},
                "targetOrder": [],
                "targetElement": "FuncFormatAlert",
                "targetAbility": "trigger"
              }
            ]
          },
          "interruptAbilities": {
            "trigger": false,
            "setup": false,
            "beep": false,
            "turnOn": false,
            "turnOff": false,
            "toggle": false,
            "setState": false
          },
          "abilities": [
            {
              "name": "trigger",
              "triggers": [
                "triggered"
              ]
            },
            {
              "name": "setup",
              "triggers": []
            },
            {
              "name": "beep",
              "triggers": []
            },
            {
              "name": "turnOn",
              "triggers": [
                "buzzerStateChange"
              ]
            },
            {
              "name": "turnOff",
              "triggers": [
                "buzzerStateChange"
              ]
            },
            {
              "name": "toggle",
              "triggers": [
                "buzzerStateChange"
              ]
            },
            {
              "name": "setState",
              "triggers": [
                "buzzerStateChange"
              ]
            }
          ]
        },
        {
          "name": "TheftAlert_Pag",
          "type": "EmbeddedIconLabelDisplay",
          "variants": [
            "embedded",
            "triggers",
            "abilities",
            "properties",
            "variables",
            "rpk"
          ],
          "properties": {
            "errorData": {},
            "code": {
              "trigger": "\treturn ATMO_Status_Success;",
              "displayPage": "\n\tATMO_UI_Page_DisplayPageByCoord(ATMO_PROPERTY(TheftAlert_Pag, x), ATMO_PROPERTY(TheftAlert_Pag, y), false);\n\treturn ATMO_Status_Success;\n\t",
              "onDisplayed": "\n\treturn ATMO_Status_Success;\n    ",
              "topRightButtonPressed": "\n\treturn ATMO_Status_Success;\n\t",
              "bottomRightButtonPressed": "\n\treturn ATMO_Status_Success;\n\t",
              "topLeftButtonPressed": "\n\treturn ATMO_Status_Success;\n\t",
              "bottomLeftButtonPressed": "\n\treturn ATMO_Status_Success;\n\t",
              "setup": "\n    ATMO_UI_PAGE_Config_t config;\n\tconfig.hidden = ATMO_PROPERTY(TheftAlert_Pag, pageHidden);\n\tconfig.textColor = ATMO_PROPERTY(TheftAlert_Pag, textColor);\n    config.activeButtons = ATMO_UI_Page_GetButtonMask(ATMO_PROPERTY(TheftAlert_Pag, topRightButtonEnabled),\n    ATMO_PROPERTY(TheftAlert_Pag,bottomRightButtonEnabled), ATMO_PROPERTY(TheftAlert_Pag, topLeftButtonEnabled), ATMO_PROPERTY(TheftAlert_Pag, bottomLeftButtonEnabled));\n\tconfig.x = ATMO_PROPERTY(TheftAlert_Pag, x);\n    config.x = ATMO_PROPERTY(TheftAlert_Pag, x);\n    config.y = ATMO_PROPERTY(TheftAlert_Pag, y);\n\tstrncpy(config.topLeftButtonLabel, ATMO_PROPERTY(TheftAlert_Pag, topLeftButtonLabel), ATMO_BUTTON_LABEL_MAXLEN);\n\tstrncpy(config.topRightButtonLabel, ATMO_PROPERTY(TheftAlert_Pag, topRightButtonLabel), ATMO_BUTTON_LABEL_MAXLEN);\n\tstrncpy(config.bottomLeftButtonLabel, ATMO_PROPERTY(TheftAlert_Pag, bottomLeftButtonLabel), ATMO_BUTTON_LABEL_MAXLEN);\n\tstrncpy(config.bottomRightButtonLabel, ATMO_PROPERTY(TheftAlert_Pag, bottomRightButtonLabel), ATMO_BUTTON_LABEL_MAXLEN);\n    config.spanX = ATMO_PROPERTY(TheftAlert_Pag, spanX);\n\tconfig.spanY = ATMO_PROPERTY(TheftAlert_Pag, spanY);\n    config.title = ATMO_PROPERTY(TheftAlert_Pag, pageTitle);\n    config.titleHidden = ATMO_PROPERTY(TheftAlert_Pag, titleHidden);\n\tATMO_UI_SINGLEICONTEXT_Init(&config);\n\tATMO_VARIABLE(TheftAlert_Pag, pageHandle) = config.templateInstance;\n    ATMO_UI_SINGLEICONTEXT_SetMainText(config.templateInstance, ATMO_PROPERTY(TheftAlert_Pag, label));\n    ATMO_UI_SINGLEICONTEXT_SetIcon(config.templateInstance, ATMO_PROPERTY(TheftAlert_Pag, icon));\n    ATMO_UI_SINGLEICONTEXT_RegisterOnDisplayedAbilityHandle(ATMO_VARIABLE(TheftAlert_Pag,pageHandle), ATMO_ABILITY(TheftAlert_Pag, onDisplayed));\n    ATMO_UI_SINGLEICONTEXT_RegisterButtonAbilityHandle(ATMO_VARIABLE(TheftAlert_Pag,pageHandle), 1, ATMO_ABILITY(TheftAlert_Pag, topRightButtonPressed));\n\tATMO_UI_SINGLEICONTEXT_RegisterButtonAbilityHandle(ATMO_VARIABLE(TheftAlert_Pag,pageHandle), 2, ATMO_ABILITY(TheftAlert_Pag, bottomRightButtonPressed));\n\tATMO_UI_SINGLEICONTEXT_RegisterButtonAbilityHandle(ATMO_VARIABLE(TheftAlert_Pag,pageHandle), 3, ATMO_ABILITY(TheftAlert_Pag, topLeftButtonPressed));\n    ATMO_UI_SINGLEICONTEXT_RegisterButtonAbilityHandle(ATMO_VARIABLE(TheftAlert_Pag,pageHandle), 4, ATMO_ABILITY(TheftAlert_Pag, bottomLeftButtonPressed));\n    ATMO_UI_SINGLEICONTEXT_RegisterOnLeaveAbilityHandle(config.templateInstance, ATMO_ABILITY(TheftAlert_Pag, onLeave));\n\treturn ATMO_Status_Success;\n    ",
              "onLeave": "\n\treturn ATMO_Status_Success;\n\t",
              "setLabel": "\n    char label[32];\n    if(ATMO_GetString(in, label, 32) == ATMO_Status_Success)\n    {\n        ATMO_UI_SINGLEICONTEXT_SetMainText(ATMO_VARIABLE(TheftAlert_Pag,pageHandle), label);\n    }\n    else\n    {\n        return ATMO_Status_Fail;\n    }\n\n    return ATMO_Status_Success;\n    "
            },
            "variables": {
              "pageHandle": {
                "type": "ATMO_DriverInstanceHandle_t"
              }
            },
            "embeddedPropertyConversions": {
              "pageTitle": "string",
              "topRightButtonLabel": "string",
              "bottomRightButtonLabel": "string",
              "topLeftButtonLabel": "string",
              "bottomLeftButtonLabel": "string",
              "label": "string"
            },
            "codeUserChanged": {
              "displayPage": false,
              "onDisplayed": false,
              "topRightButtonPressed": false,
              "bottomRightButtonPressed": false,
              "topLeftButtonPressed": false,
              "bottomLeftButtonPressed": false,
              "setup": false,
              "onLeave": false,
              "setLabel": false
            },
            "textColor": "GUI_RED",
            "pageTitle": "Motion monitor",
            "titleHidden": false,
            "pageHidden": false,
            "topRightButtonLabel": "",
            "topRightButtonEnabled": false,
            "bottomRightButtonLabel": "",
            "bottomRightButtonEnabled": false,
            "topLeftButtonLabel": "",
            "topLeftButtonEnabled": false,
            "bottomLeftButtonLabel": "",
            "bottomLeftButtonEnabled": false,
            "x": "0",
            "y": "0",
            "spanX": "1",
            "spanY": 1,
            "icon": "icon_applications_motion",
            "label": "Beehive OK"
          },
          "meta": {
            "editorX": 751.1666870117188,
            "editorY": 139,
            "lastTrigger": "onDisplayed"
          },
          "triggers": {
            "triggered": [],
            "onDisplayed": [],
            "topRightButtonPressed": [],
            "bottomRightButtonPressed": [],
            "topLeftButtonPressed": [],
            "bottomLeftButtonPressed": [],
            "onLeave": []
          },
          "interruptAbilities": {
            "trigger": false,
            "displayPage": false,
            "onDisplayed": false,
            "topRightButtonPressed": false,
            "bottomRightButtonPressed": false,
            "topLeftButtonPressed": false,
            "bottomLeftButtonPressed": false,
            "setup": false,
            "onLeave": false,
            "setLabel": false
          },
          "abilities": [
            {
              "name": "trigger",
              "triggers": [
                "triggered"
              ]
            },
            {
              "name": "displayPage",
              "triggers": []
            },
            {
              "name": "onDisplayed",
              "triggers": [
                "onDisplayed"
              ]
            },
            {
              "name": "topRightButtonPressed",
              "triggers": [
                "topRightButtonPressed"
              ]
            },
            {
              "name": "bottomRightButtonPressed",
              "triggers": [
                "bottomRightButtonPressed"
              ]
            },
            {
              "name": "topLeftButtonPressed",
              "triggers": [
                "topLeftButtonPressed"
              ]
            },
            {
              "name": "bottomLeftButtonPressed",
              "triggers": [
                "bottomLeftButtonPressed"
              ]
            },
            {
              "name": "setup",
              "triggers": []
            },
            {
              "name": "onLeave",
              "triggers": [
                "onLeave"
              ]
            },
            {
              "name": "setLabel",
              "triggers": []
            }
          ]
        },
        {
          "name": "MotionRead",
          "type": "EmbeddedFunction",
          "variants": [
            "embedded",
            "triggers",
            "abilities",
            "properties",
            "variables"
          ],
          "properties": {
            "errorData": {},
            "code": {
              "trigger": "    ATMO_CreateValueString(out, \"Theft Alert!\");"
            },
            "variables": {},
            "embeddedPropertyConversions": {},
            "codeUserChanged": {
              "trigger": true
            }
          },
          "meta": {
            "editorX": 350.33349609375,
            "editorY": 141,
            "lastTrigger": "triggered"
          },
          "triggers": {
            "triggered": [
              {
                "mapping": {},
                "targetOrder": [],
                "targetElement": "TheftAlert_Pag",
                "targetAbility": "setLabel"
              },
              {
                "mapping": {},
                "targetOrder": [],
                "targetElement": "TheftAlert_Pag",
                "targetAbility": "displayPage"
              }
            ]
          },
          "interruptAbilities": {
            "trigger": false
          },
          "abilities": [
            {
              "name": "trigger",
              "triggers": [
                "triggered"
              ]
            }
          ]
        },
        {
          "name": "ResetTheftAlert",
          "type": "EmbeddedFunction",
          "variants": [
            "embedded",
            "triggers",
            "abilities",
            "properties",
            "variables"
          ],
          "properties": {
            "errorData": {},
            "code": {
              "trigger": "\tATMO_CreateValueString(out, \"Beehive OK\");\n\treturn ATMO_Status_Success;"
            },
            "variables": {},
            "embeddedPropertyConversions": {},
            "codeUserChanged": {
              "trigger": true
            }
          },
          "meta": {
            "editorX": 653.1666870117188,
            "editorY": 242,
            "lastTrigger": "triggered"
          },
          "triggers": {
            "triggered": [
              {
                "mapping": {},
                "targetOrder": [],
                "targetElement": "TheftAlert_Pag",
                "targetAbility": "setLabel"
              }
            ]
          },
          "interruptAbilities": {
            "trigger": false
          },
          "abilities": [
            {
              "name": "trigger",
              "triggers": [
                "triggered"
              ]
            }
          ]
        },
        {
          "name": "EmbeddedNxpRpkRgbLed",
          "type": "EmbeddedNxpRpkRgbLed",
          "variants": [
            "embedded",
            "triggers",
            "abilities",
            "properties",
            "variables",
            "rpk"
          ],
          "properties": {
            "errorData": {},
            "code": {
              "trigger": "\treturn ATMO_Status_Success;",
              "setup": "\n    RGB_Led_Set_State(RGB_LED_BRIGHT_HIGH, RGB_LED_COLOR_BLACK);\n\treturn ATMO_Status_Success;\n\t",
              "setColorPreset": "\n    unsigned int desiredColor = 0;\n    ATMO_GetUnsignedInt(in, &desiredColor);\n\n    uint8_t brightness = 0;\n    uint8_t color = 0;\n    RGB_Led_Get_State(&brightness, &color);\n    RGB_Led_Set_State(brightness, desiredColor);\n    return ATMO_Status_Success;\n    ",
              "setBrightnessLow": "\n    uint8_t brightness = 0;\n    uint8_t color = 0;\n    RGB_Led_Get_State(&brightness, &color);\n    RGB_Led_Set_State(RGB_LED_BRIGHT_LOW, color);\n    return ATMO_Status_Success;\n    ",
              "setBrightnessOff": "\n    uint8_t brightness = 0;\n    uint8_t color = 0;\n    RGB_Led_Get_State(&brightness, &color);\n    RGB_Led_Set_State(RGB_LED_BRIGHT_OFF, color);\n    return ATMO_Status_Success;\n    ",
              "setBrightnessMedium": "\n    uint8_t brightness = 0;\n    uint8_t color = 0;\n    RGB_Led_Get_State(&brightness, &color);\n    RGB_Led_Set_State(RGB_LED_BRIGHT_MEDIUM, color);\n    return ATMO_Status_Success;\n    ",
              "setBrightnessHigh": "\n    uint8_t brightness = 0;\n    uint8_t color = 0;\n    RGB_Led_Get_State(&brightness, &color);\n    RGB_Led_Set_State(RGB_LED_BRIGHT_HIGH, color);\n    return ATMO_Status_Success;\n    ",
              "setRedOn": "\n    RGB_Led_Set_State(RGB_LED_BRIGHT_HIGH, RGB_LED_COLOR_RED);\n\treturn ATMO_Status_Success;\n    ",
              "setGreenOn": "\n    RGB_Led_Set_State(RGB_LED_BRIGHT_HIGH, RGB_LED_COLOR_GREEN);\n\treturn ATMO_Status_Success;\n    ",
              "setBlueOn": "\n    RGB_Led_Set_State(RGB_LED_BRIGHT_HIGH, RGB_LED_COLOR_BLUE);\n\treturn ATMO_Status_Success;\n    ",
              "setWhiteOn": "\treturn ATMO_Status_Success;",
              "toggleRed": "\n\tuint8_t color, brightness;\n    RGB_Led_Get_State(&brightness, &color);\n    if(brightness == RGB_LED_BRIGHT_OFF || color == RGB_LED_COLOR_BLACK)\n    {\n        brightness = RGB_LED_BRIGHT_HIGH;\n    }\n    else\n    {\n        brightness = RGB_LED_BRIGHT_OFF;\n    }\n\n    RGB_Led_Set_State(brightness, RGB_LED_COLOR_RED);\n    return ATMO_Status_Success;\n\t",
              "toggleGreen": "\n\tuint8_t color, brightness;\n    RGB_Led_Get_State(&brightness, &color);\n    if(brightness == RGB_LED_BRIGHT_OFF || color == RGB_LED_COLOR_BLACK)\n    {\n        brightness = RGB_LED_BRIGHT_HIGH;\n    }\n    else\n    {\n        brightness = RGB_LED_BRIGHT_OFF;\n    }\n\n    RGB_Led_Set_State(brightness, RGB_LED_COLOR_GREEN);\n    return ATMO_Status_Success;\n\t",
              "toggleBlue": "\n\tuint8_t color, brightness;\n    RGB_Led_Get_State(&brightness, &color);\n    if(brightness == RGB_LED_BRIGHT_OFF || color == RGB_LED_COLOR_BLACK)\n    {\n        brightness = RGB_LED_BRIGHT_HIGH;\n    }\n    else\n    {\n        brightness = RGB_LED_BRIGHT_OFF;\n    }\n\n    RGB_Led_Set_State(brightness, RGB_LED_COLOR_BLUE);\n    return ATMO_Status_Success;\n\t",
              "setOff": "\n    uint8_t color, brightness;\n    RGB_Led_Get_State(&brightness, &color);\n    RGB_Led_Set_State(brightness, RGB_LED_COLOR_BLACK);\n\treturn ATMO_Status_Success;\n    ",
              "setColorHex": "\n    unsigned int color = 0;\n    ATMO_GetUnsignedInt(in, &color);\n    uint8_t red = (color >> 16) & 0xFF;\n    uint8_t green = (color >> 8) & 0xFF;\n    uint8_t blue = color & 0xFF;\n    Rgb_Led_Set_Colors(red, green, blue);  \n    ATMO_CreateValueUnsignedInt(out, color);\n\treturn ATMO_Status_Success;\n    "
            },
            "variables": {},
            "embeddedPropertyConversions": {},
            "codeUserChanged": {
              "setup": false,
              "setColorPreset": false,
              "setBrightnessLow": false,
              "setBrightnessOff": false,
              "setBrightnessMedium": false,
              "setBrightnessHigh": false,
              "setRedOn": false,
              "setGreenOn": false,
              "setBlueOn": false,
              "setWhiteOn": false,
              "toggleRed": false,
              "toggleGreen": false,
              "toggleBlue": false,
              "setOff": false,
              "setColorHex": false
            }
          },
          "meta": {
            "editorX": 753.1666870117188,
            "editorY": 41,
            "lastTrigger": "colorSet"
          },
          "triggers": {
            "triggered": [],
            "brightnessSet": [],
            "colorSet": []
          },
          "interruptAbilities": {
            "trigger": false,
            "setup": false,
            "setColorPreset": false,
            "setBrightnessLow": false,
            "setBrightnessOff": false,
            "setBrightnessMedium": false,
            "setBrightnessHigh": false,
            "setRedOn": false,
            "setGreenOn": false,
            "setBlueOn": false,
            "setWhiteOn": false,
            "toggleRed": false,
            "toggleGreen": false,
            "toggleBlue": false,
            "setOff": false,
            "setColorHex": false
          },
          "abilities": [
            {
              "name": "trigger",
              "triggers": [
                "triggered"
              ]
            },
            {
              "name": "setup",
              "triggers": []
            },
            {
              "name": "setColorPreset",
              "triggers": []
            },
            {
              "name": "setBrightnessLow",
              "triggers": [
                "brightnessSet"
              ]
            },
            {
              "name": "setBrightnessOff",
              "triggers": [
                "brightnessSet"
              ]
            },
            {
              "name": "setBrightnessMedium",
              "triggers": [
                "brightnessSet"
              ]
            },
            {
              "name": "setBrightnessHigh",
              "triggers": [
                "brightnessSet"
              ]
            },
            {
              "name": "setRedOn",
              "triggers": []
            },
            {
              "name": "setGreenOn",
              "triggers": []
            },
            {
              "name": "setBlueOn",
              "triggers": []
            },
            {
              "name": "setWhiteOn",
              "triggers": []
            },
            {
              "name": "toggleRed",
              "triggers": []
            },
            {
              "name": "toggleGreen",
              "triggers": []
            },
            {
              "name": "toggleBlue",
              "triggers": []
            },
            {
              "name": "setOff",
              "triggers": []
            },
            {
              "name": "setColorHex",
              "triggers": [
                "colorSet"
              ]
            }
          ]
        },
        {
          "name": "SigfoxModem",
          "type": "EmbeddedSigfoxClick",
          "variants": [
            "embedded",
            "triggers",
            "abilities",
            "properties",
            "variables"
          ],
          "properties": {
            "errorData": {},
            "code": {
              "trigger": "\treturn ATMO_Status_Success;",
              "setup": "    ATMO_SIGFOX_CLICK_Config_t config;\r\n    config.spiInstance = ATMO_PROPERTY(SigfoxModem, spiDriverInstance);\r\n    config.gpioInstance = ATMO_PROPERTY(SigfoxModem, gpioDriverInstance);\r\n    config.csPin = ATMO_PROPERTY(SigfoxModem, csPin);\r\n    config.rstPin = ATMO_PROPERTY(SigfoxModem, rstPin);\r\n    config.ackPin = ATMO_PROPERTY(SigfoxModem, ackPin);\r\n    config.txAtten = ATMO_PROPERTY(SigfoxModem, txAtten);\r\n    config.netStandard = ATMO_PROPERTY(SigfoxModem, netStandard);\r\n    config.usePublicKey = ATMO_PROPERTY(SigfoxModem, publicKey);\r\n    ATMO_SIGFOX_CLICK_RegisterAbilityHandle(ATMO_SIGFOX_CLICK_EVENT_PayloadSent, ATMO_ABILITY(SigfoxModem, payloadSent));\r\n    ATMO_SIGFOX_CLICK_RegisterAbilityHandle(ATMO_SIGFOX_CLICK_EVENT_ResponseReceived, ATMO_ABILITY(SigfoxModem, responseReceived));\r\n    ATMO_SIGFOX_CLICK_RegisterAbilityHandle(ATMO_SIGFOX_CLICK_EVENT_Error, ATMO_ABILITY(SigfoxModem, txRxError));\r\n    return ATMO_SIGFOX_CLICK_Init(&config) == ATMO_SIGFOX_CLICK_Status_Success ? ATMO_Status_Success : ATMO_Status_Fail;",
              "sendPayload": "    ATMO_Value_t payloadValue;\r\n    ATMO_InitValue(&payloadValue);\r\n    ATMO_CreateValueConverted(&payloadValue, ATMO_PROPERTY(SigfoxModem, upstreamDataType), in);\r\n    ATMO_SIGFOX_CLICK_Status_t status = ATMO_SIGFOX_CLICK_SendPayload(payloadValue.data, payloadValue.size, false);\r\n    ATMO_FreeValue(&payloadValue);\r\n    return status == ATMO_SIGFOX_CLICK_Status_Success ? ATMO_Status_Success : ATMO_Status_Fail;",
              "sendPayloadReqResponse": "    ATMO_Value_t payloadValue;\r\n    ATMO_InitValue(&payloadValue);\r\n    ATMO_CreateValueConverted(&payloadValue, ATMO_PROPERTY(SigfoxModem, upstreamDataType), in);\r\n    ATMO_SIGFOX_CLICK_Status_t status = ATMO_SIGFOX_CLICK_SendPayload(payloadValue.data, payloadValue.size, true);\r\n    ATMO_FreeValue(&payloadValue);\r\n    return status == ATMO_SIGFOX_CLICK_Status_Success ? ATMO_Status_Success : ATMO_Status_Fail;",
              "getDeviceId": "    sf_device_info_t info;\r\n    ATMO_SIGFOX_CLICK_Status_t status = ATMO_SIGFOX_CLICK_GetDeviceInfo(&info);\r\n\r\n    if(status != ATMO_SIGFOX_CLICK_Status_Success)\r\n    {\r\n        return ATMO_Status_Fail;\r\n    }\r\n\r\n    char devIdStr[9] = {0};\r\n\r\n    sprintf(devIdStr, \"%02X%02X%02X%02X\", \r\n    (info.devId >> 24) & 0xFF,\r\n    (info.devId >> 16) & 0xFF,\r\n    (info.devId >> 8) & 0xFF,\r\n    (info.devId) & 0xFF);\r\n\r\n    ATMO_CreateValueString(out, devIdStr);\r\n    return ATMO_Status_Success;",
              "getPac": "    sf_device_info_t info;\r\n    ATMO_SIGFOX_CLICK_Status_t status = ATMO_SIGFOX_CLICK_GetDeviceInfo(&info);\r\n\r\n    if(status != ATMO_SIGFOX_CLICK_Status_Success)\r\n    {\r\n        return ATMO_Status_Fail;\r\n    }\r\n\r\n    char devPacStr[17] = {0};\r\n\r\n    sprintf(devPacStr, \"%02X%02X%02X%02X%02X%02X%02X%02X\", \r\n        info.devPac[0],\r\n        info.devPac[1],\r\n        info.devPac[2],\r\n        info.devPac[3],\r\n        info.devPac[4],\r\n        info.devPac[5],\r\n        info.devPac[6],\r\n        info.devPac[7]);\r\n\r\n    ATMO_CreateValueString(out, devPacStr);\r\n    return ATMO_Status_Success;",
              "payloadSent": "return ATMO_Status_Success;",
              "responseReceived": "    ATMO_CreateValueConverted(out, ATMO_PROPERTY(SigfoxModem, downstreamDataType), in);\r\n    return ATMO_Status_Success;",
              "txRxError": "return ATMO_Status_Success;"
            },
            "variables": {},
            "embeddedPropertyConversions": {},
            "codeUserChanged": {
              "setup": false,
              "sendPayload": false,
              "sendPayloadReqResponse": false,
              "getDeviceId": false,
              "getPac": false,
              "payloadSent": false,
              "responseReceived": false,
              "txRxError": false
            },
            "gpioDriverInstance": "ATMO_DRIVERINSTANCE_GPIO_GPIO1",
            "spiDriverInstance": "ATMO_DRIVERINSTANCE_SPI_SPI1",
            "csPin": "MB3_CS",
            "ackPin": "MB3_AN",
            "rstPin": "MB3_RST",
            "netStandard": "sfNetStandardETSI",
            "txAtten": 0,
            "publicKey": false,
            "upstreamDataType": "ATMO_DATATYPE_FLOAT",
            "downstreamDataType": "ATMO_DATATYPE_FLOAT"
          },
          "meta": {
            "editorX": 500.33349609375,
            "editorY": 241,
            "lastTrigger": "payloadSent"
          },
          "triggers": {
            "triggered": [],
            "deviceIdRetrieved": [],
            "pacRetrieved": [],
            "payloadSent": [
              {
                "mapping": {},
                "targetOrder": [],
                "targetElement": "ResetTheftAlert",
                "targetAbility": "trigger"
              },
              {
                "mapping": {},
                "targetOrder": [],
                "targetElement": "EmbeddedNxpRpkRgbLed",
                "targetAbility": "setOff"
              }
            ],
            "responseReceived": [],
            "txRxError": []
          },
          "interruptAbilities": {
            "trigger": false,
            "setup": false,
            "sendPayload": false,
            "sendPayloadReqResponse": false,
            "getDeviceId": false,
            "getPac": false,
            "payloadSent": false,
            "responseReceived": false,
            "txRxError": false
          },
          "abilities": [
            {
              "name": "trigger",
              "triggers": [
                "triggered"
              ]
            },
            {
              "name": "setup",
              "triggers": []
            },
            {
              "name": "sendPayload",
              "triggers": []
            },
            {
              "name": "sendPayloadReqResponse",
              "triggers": []
            },
            {
              "name": "getDeviceId",
              "triggers": [
                "deviceIdRetrieved"
              ]
            },
            {
              "name": "getPac",
              "triggers": [
                "pacRetrieved"
              ]
            },
            {
              "name": "payloadSent",
              "triggers": [
                "payloadSent"
              ]
            },
            {
              "name": "responseReceived",
              "triggers": [
                "responseReceived"
              ]
            },
            {
              "name": "txRxError",
              "triggers": [
                "txRxError"
              ]
            }
          ]
        },
        {
          "name": "FuncFormatAlert",
          "type": "EmbeddedFunction",
          "variants": [
            "embedded",
            "triggers",
            "abilities",
            "properties",
            "variables"
          ],
          "properties": {
            "errorData": {},
            "code": {
              "trigger": "    float talert = -100;\n\tATMO_CreateValueFloat(out, talert); //Theft Alert\n\treturn ATMO_Status_Success;"
            },
            "variables": {},
            "embeddedPropertyConversions": {},
            "codeUserChanged": {
              "trigger": true
            }
          },
          "meta": {
            "editorX": 352.33349609375,
            "editorY": 240,
            "lastTrigger": "triggered"
          },
          "triggers": {
            "triggered": [
              {
                "mapping": {},
                "targetOrder": [],
                "targetElement": "SigfoxModem",
                "targetAbility": "sendPayload"
              }
            ]
          },
          "interruptAbilities": {
            "trigger": false
          },
          "abilities": [
            {
              "name": "trigger",
              "triggers": [
                "triggered"
              ]
            }
          ]
        },
        {
          "name": "ENS210TemperatureHumidity1",
          "type": "EmbeddedENS210",
          "variants": [
            "embedded",
            "triggers",
            "abilities",
            "properties",
            "variables"
          ],
          "properties": {
            "errorData": {},
            "code": {
              "trigger": "\treturn ATMO_Status_Success;",
              "setup": "\tATMO_ENS210_Config_t config;\n\tconfig.address = ATMO_PROPERTY(ENS210TemperatureHumidity1, i2cAddress);\n\tconfig.i2cDriverInstance = ATMO_PROPERTY(ENS210TemperatureHumidity1, i2cInstance);\n\tconfig.tempCalibrationOffset = ATMO_PROPERTY(ENS210TemperatureHumidity1, tempCalibrationOffset);\n\n\treturn ( ATMO_ENS210_Init(&config) == ATMO_ENS210_Status_Success ) ? ATMO_Status_Success : ATMO_Status_Fail;\n",
              "setEnabled": "ATMO_ENS210_SetEnabled(true);\nreturn ATMO_Status_Success;",
              "setDisabled": "ATMO_ENS210_SetEnabled(false);\nreturn ATMO_Status_Success;",
              "setEnabledDisabled": "bool enabled = false;\nATMO_GetBool(in, &enabled);\nATMO_ENS210_SetEnabled(enabled);\nreturn ATMO_Status_Success;",
              "readTemperature": "    float tempC;\n    \n    if(ATMO_ENS210_GetTemperatureFloat(&tempC) == ATMO_ENS210_Status_Success)\n    {\n        ATMO_CreateValueFloat(out, tempC);\n    }\n    else\n    {\n        ATMO_CreateValueVoid(out);\n    }\n    \n    return ATMO_Status_Success;",
              "readHumidity": "    float humidityPct;\n\n    if(ATMO_ENS210_GetHumidityFloat(&humidityPct) == ATMO_ENS210_Status_Success)\n    {\n        ATMO_CreateValueFloat(out, humidityPct);\n    }\n    else\n    {\n        ATMO_CreateValueVoid(out);\n    }\n    \n    return ATMO_Status_Success;"
            },
            "variables": {},
            "embeddedPropertyConversions": {},
...

This file has been truncated, please download it to see its full contents.

REST API to handle SigFox Callback

PHP
This simple REST API receives the callback from SigFox backend, stores the data to database and alerts user in case of theft event detected.
<?php
/*
REST API for NXP Rapid IoT Kit SigFox beehive monitor

Sigfox Callback format
http://itrubec.cz/monitor/NXPmonitorData.php?key=xxxxxx&dev={device}&t1={customData#t1}&rssi={rssi}&seqn={seqNumber}&lat={lat}&lng={lng}&snr={snr}&avgsnr={avgSnr}

example GET (sending POST in reality)


SigFox message format
t1::float:32:little-endian
*/

$_GET   = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING);
$_POST  = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);

echo("test<br>");

$servername = "xxx";   //server name
$username = "xxx";       //DB login
$password = "xxx";//DB psswd
$dbname = "xxx";       //DB name

// Create connection
$mysqli =  new mysqli($servername, $username, $password, $dbname);

/* check connection */
if ($mysqli->connect_errno) {
    printf("Connect failed: %s\n", $mysqli->connect_error);
    exit();
}

/*
DB TABLES STRUCTURE

CREATE TABLE IF NOT EXISTS `monitor_devices` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user` int(11) NOT NULL,
  `device` varchar(255) NOT NULL,
  `devkey` varchar(255) NOT NULL,
  `enabled` tinyint(1) NOT NULL,
  `registered` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `lastactivity` timestamp NULL DEFAULT NULL,
  `note` text,
  PRIMARY KEY (`id`),
  KEY `device` (`device`),
  KEY `key` (`key`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COMMENT='List of known devices' AUTO_INCREMENT=2 ;


CREATE TABLE IF NOT EXISTS `monitor_data` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `devid` int(11) NOT NULL,
  `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `temp1` int(11) DEFAULT NULL,
  `temp2` int(11) DEFAULT NULL,
  `temp3` int(11) DEFAULT NULL,
  `humidity1` int(11) DEFAULT NULL,
  `pressure1` int(11) DEFAULT NULL,
  `batteryvoltage` float DEFAULT NULL,
  `rssi` float DEFAULT NULL,
  `seqn` bigint(20) DEFAULT NULL,
  `lat` float DEFAULT NULL,
  `lng` float DEFAULT NULL,
  `snr` float DEFAULT NULL,
  `avgsnr` float DEFAULT NULL,
  `TheftAlert` tinyint(1) DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `devid` (`devid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Data received from SigFox callBack' AUTO_INCREMENT=1 ;
*/

//http://itrubec.cz/monitor/newdata.php?key=xxxxxx&dev=xxxxxx&t1=76&rssi=-136.00&seqn=23&lat=49.0&lng=17.0&snr=11.84&avgsnr=23.84
/*
$key = $_POST["key"];
$dev = $_POST["dev"];
$t1 = $_POST["t1"];
$rssi = $_POST["rssi"];
$seqn = $_POST["seqn"];
$lat = $_POST["lat"];
$lng = $_POST["lng"];
$snr = $_POST["snr"];
$avgsnr = $_POST["avgsnr"];
*/
$key = $_GET["key"];
$dev = $_GET["dev"];
$t1 = $_GET["t1"];
$rssi = $_GET["rssi"];
$seqn = $_GET["seqn"];
$lat = $_GET["lat"];
$lng = $_GET["lng"];
$snr = $_GET["snr"];
$avgsnr = $_GET["avgsnr"];

//SELECT ID FROM `monitor_devices` WHERE devkey like "xxxxxx" AND device like "xxxxx"
$sql = "SELECT ID FROM `monitor_devices` WHERE devkey like \"".$key."\" AND device like \"".$dev."\"";
if ($result = $mysqli->query($sql)) {
    printf("%d device found in catalogue.\n", $result->num_rows);
    $row=mysqli_fetch_row($result);
    $devid = $row[0];
    $result->close();
    $sql = "UPDATE `monitor_devices` SET `lastactivity`=now() WHERE `id`=".$devid;
    //echo($sql);
    echo("<br>");
    if ($mysqli->query($sql) === TRUE) {
      printf("Last activity of device updated.<br>\n");
    }
}else{
   die("Bad key or bad device!");
}

$sql = "SELECT ID FROM `monitor_devices`";

if ($t1 < -60) { //Theft Alert
   $sql = "INSERT INTO `monitor_data`(`devid`, `timestamp`, `rssi`, `seqn`, `lat`, `lng`, `snr`, `avgsnr`, `TheftAlert`) VALUES ($devid, now(),$rssi,$seqn,$lat,$lng,$snr,$avgsnr,1)";
   //SMS alert!

   $to = "???????????@sms.cz.o2.com";
   $subject = "Theft Alert";
   $txt = "Motion detected at beehive #".$dev;
   $headers = 'From: x@xx.cz' . "\r\n" .
    'Reply-To: x@xx.cz' . "\r\n" .
    'Cc: x@xx.cz' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
   mail($to,$subject,$txt,$headers);

}

if (($t1 > -60) && ($t1 < 100)) { //Temperature
   $sql = "INSERT INTO `monitor_data`(`devid`, `timestamp`, `temp1`, `rssi`, `seqn`, `lat`, `lng`, `snr`, `avgsnr`) VALUES ($devid, now(),$t1,$rssi,$seqn,$lat,$lng,$snr,$avgsnr)";
}

if (($t1 >= 100) && ($t1 < 201)) { //Humidity
   $t1 = $t1 - 100;
   $sql = "INSERT INTO `monitor_data`(`devid`, `timestamp`, `humidity1`, `rssi`, `seqn`, `lat`, `lng`, `snr`, `avgsnr`) VALUES ($devid, now(),$t1,$rssi,$seqn,$lat,$lng,$snr,$avgsnr)";
}

if (($t1 > 850) && ($t1 < 1100)) { //Atmospheric Pressure
   $sql = "INSERT INTO `monitor_data`(`devid`, `timestamp`, `pressure1`, `rssi`, `seqn`, `lat`, `lng`, `snr`, `avgsnr`) VALUES ($devid, now(),$t1,$rssi,$seqn,$lat,$lng,$snr,$avgsnr)";
}

//$sql = "INSERT INTO `monitor_data`(`devid`, `timestamp`, `temp1`, `temp2`, `temp3`, `humidity1`, `pressure1`, `batteryvoltage`, `rssi`, `seqn`, `lat`, `lng`, `snr`, `avgsnr`) VALUES ($devid, now(),$t1,$t2,$t3,$v1,$p1,$n1,$rssi,$seqn,$lat,$lng,$snr,$avgsnr)";

if ($result = $mysqli->query($sql)) {
    echo "OK";
} else {
    echo "Error" . $sql;
}

$mysqli->close();
?>

Credits

Vilém Kužel

Vilém Kužel

7 projects • 22 followers
https://www.linkedin.com/in/vilemkuzel/

Comments