fullstackIOT - mckennatim/gitinfo GitHub Wiki

<home

the IOT fullstack

Is comprised of

  • ESP C++ code on devices (e:/fs/iot3)
  • MQTT broker (nginx node)
  • Express server (nginx node)
  • MYSQL database
  • MongoDB database (for broker and auth)
  • Authentication Shared by all iot apps and regular apps

The project build system creates a custom project based on fs/iot3/my base project. It sets up a new conf/, from which the specifics of the custom project can be specified.

Building a project from my/conf/projectid/ copies the CONFIG.cpp and CONFIG.h files into the my/src directory. It also sends information to the server's database so the project can be identified and authorized by the server.

Each project has an associated react app. That app uses the information in a appInit.js file in the conf directory. That file gets copied to the react app.

Now you go to my/src/main.cpp and tweak it until the it compiles and does what it is supposed to do. From the conf/appid/devid directory you can run 'getMain.js` to have a copy of the tweaked main.cpp file associtaed with each project and device.

incremental improvement 1/23

ESP (e:/fs/iot3) for better recovery from loss of wifi and to drop back to default code when not connected

FrontEnd (/home/tim/www/react/v18/iot) replacing of navigo and redux with context and history for a more responsive/multipane setup. No longer using the mqtt-hooks in the npm repo.

Authentication Signin - Either figure out a way to use a hooks2/iot/signin from /v18/iot and similar in production, OR add signin within every app.

git

There are two different scripts for a new commit and a copy of tag to tags. For fs/iot3 use git.ps1 o7-tag_name

For wsl www projects, use git.sh o7-tag_name which is global in /home/tim/.scripts

steps to begin a project

In the IOTstack

  • Have the most recent, my project config that compiles and runs and does most of the things you need in the my folder.
    • COMPILE AND RUN oneof the apps that uses that device. Repeat for each device. On the Serial.monitor the app should have requested the time and gotten it back.
  • In the current IOT device stack's fs/iot3/my/conf' add a direcotry ###APPID containing a directory for every processor used (containing CONFIG.cpp, CONFIG.h files for that device) plus an APPID.md and APPID.json. Copy CONFIG.cpp and CONFIG.h from my/srs to my/conf/###APPID/DEVID

Making a new mqtt connection

As soon as you change the devid the ability to connect to MQTT is compromised.(Device should still be able to getOnline to WIFI) Core connection information for mqqt is as follows

/*SERVER dev extern device variables*/
bool haywifi=true
char devid[9]="CYURD126";
char owner[254]="[email protected]";
char pwd[24]="geniot";
char mqtt_server[60]="sitebuilt.net";
char mqtt_port[6]="1884";

In order to connect to MQTT, this minumum info must be in the MYSQL geniot database devs table

INSERT INTO `devs` (`id`, `devid`, `owner` `devpwd`, `locid`, `description`) VALUES (NULL, 'CYURD127', 
'[email protected]',
'geniot',
'255ChestnutAve',
'doorStrike with strike RGB LEDs and contacts. Part of entry system project that has doorbells, camera and aprtment UI.'
)

Every device has to be somewhere. The locid is required but not by the device code.

COMPILE AND RUN before the table insert will stall at the MQTT connection

COMPILE AND RUN after the table insert shoud take you to the time and date payload.

Apps need users and locations

Select one of the appids that will use this device. Let the database know at least one app_loc_user combination.

INSERT INTO `app_loc_user` (`id`, `appid`, `user` `role`) VALUES (NULL,
'doorStrike'
'[email protected]',
'255ChestnutAve',
'admin'
);

Now the doorStrike app will show up in the 255ChestnutAve list for `[email protected].

Do additional inserts to allow that app to run in other locations and/or by other users

INSERT INTO `app_loc_user` (`id`, `appid`, `user` `role`) VALUES (NULL,
'doorStrike'
'[email protected]',
'255ChestnutAve',
'admin'
);
  • Write a project description narrative and identify an DEVID for the ESP DEVIDS needed, the inputs and outputs for for each device and an APPID. Covert description to .js file

    const devs = 
    { 
      "CYURD127": [
        {
          "sr": 0,
          "label": "contact" ,
          "type": "se",
          "io": "input",
          "port": "D4",
        },
        {
          "sr": 1,
          "label": "redLED",
          "type": "rel",
          "io": "output",
          "port": "D8",
        },
        {
          "sr": 2,
          "label": "greenLED",
          "type": "rel",
          "io": "output",
          "port": "D7",
        },
        {
          "sr":3,
          "label": "blueLED",
          "type": "rel",
          "io": "output",
          "port": "D6",
        },
        {
          "sr": 4,
          "label": "strike",
          "type": "rel",
          "io": "output",
          "port": "D1"
        }
      ]
    }
    
    const zones = 
    [
      {
        "id": "contact",
        "name": "NC magnetic door contact",
        "img": "contact.jpg"
      },
      {
        "id": "redLED",
        "name": "closed & locked: redLED",
        "img": "redLED.jpg"
      },
      {
        "id": "greenLED",
        "name": "unlocked: greenLED",
        "img": "greenLED.jpg"
      },
      {
        "id": "blueLED",
        "name": "open: blueLED",
        "img": "blueLED.jpg"
      },
      {
        "id": "strike",
        "name": "Door Strike",
        "img": "strike.jpg"
      }
    ]
    

CONFIF.cpp and CONFIG.h will need to be modified

/*PORTS for the index of the array == the sr#*/
const ports_t ports {
  {D4, INPUT},
  {D8, OUTPUT},
  {D7, OUTPUT},
  {D6, OUTPUT},
  {D2, OUTPUT},
}

The SQL commands to add the app, loc and dev to the geniot database are created from doorStrike.js data structures. These are converted into SQL commands via index.js

CONFIG.cpp and CONFIG.h couls also be generated.

The initialStates of the app can also be generated via index.js and doorStrike.js

COMPILE AND RUN after initialStates is in the app and devs and zones are in app_loc. Now you should see NEW_MAIL request coming into the pio monitor.

Rinse, wash, repeat from IOT to frontend.

⚠️ **GitHub.com Fallback** ⚠️