File size: 10,679 Bytes
9e03f43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
478efdc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9e03f43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
478efdc
 
 
 
 
 
 
 
 
 
 
 
9e03f43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
478efdc
 
9e03f43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
from __future__ import annotations

import textwrap

import gradio as gr


GITHUB = "https://github.com/ThingsLog"
THINGSLOG = "https://thingslog.com"

STACKS = {
    "React portal": {
        "repo": "thingslog-monitoring-portal-template",
        "best_for": "A polished single-page monitoring portal for demos, pilots, installers, and customer-facing dashboards.",
        "start": "npm install && npm run dev",
    },
    "Next.js portal": {
        "repo": "thingslog-nextjs-monitoring-template",
        "best_for": "Production-style partner portals with server-side token handling and customer workspaces.",
        "start": "npm install && npm run dev",
    },
    "Vue portal": {
        "repo": "thingslog-vue-monitoring-template",
        "best_for": "Vue teams building lightweight monitoring, alerting, and reporting tools.",
        "start": "npm install && npm run dev",
    },
    "Node API": {
        "repo": "thingslog-node-express-api-template",
        "best_for": "Backend gateway for keeping ThingsLog tokens server-side and exposing partner-specific APIs.",
        "start": "npm install && npm run dev",
    },
    "Python FastAPI": {
        "repo": "thingslog-python-fastapi-template",
        "best_for": "Utility IT teams, automation, reporting jobs, data exports, and integration services.",
        "start": "python -m venv .venv && source .venv/bin/activate && pip install -r requirements.txt && uvicorn app.main:app --reload",
    },
    "API starter kit": {
        "repo": "thingslog-api-starter-kit",
        "best_for": "Learning the ThingsLog REST API, token flow, counters, alarms, device metadata, and Push API integration.",
        "start": "Open the README and run the curl examples from a secure terminal.",
    },
}

REPOSITORIES = [
    (
        "thingslog-api-starter-kit",
        "REST API guide, token flow, counters, alarms, devices, and Push API examples.",
    ),
    (
        "thingslog-monitoring-portal-template",
        "React/Vite monitoring portal for fast demos and installer-facing dashboards.",
    ),
    (
        "thingslog-nextjs-monitoring-template",
        "Next.js portal skeleton for partner products with backend token handling.",
    ),
    (
        "thingslog-vue-monitoring-template",
        "Vue starter app for lightweight monitoring and alerting portals.",
    ),
    (
        "thingslog-node-express-api-template",
        "Node/Express backend gateway for ThingsLog API integration.",
    ),
    (
        "thingslog-python-fastapi-template",
        "Python/FastAPI service for utility IT teams, automation, and reports.",
    ),
    (
        "thingslog-ai-examples",
        "Codex and Claude prompts, app briefs, launch checklist, and setup guides.",
    ),
]


def repo_url(repo: str) -> str:
    return f"{GITHUB}/{repo}"


def build_prompt(stack: str, customer_type: str, solution: str, agent: str) -> str:
    item = STACKS[stack]
    return textwrap.dedent(
        f"""
        You are {agent}, helping build a ThingsLog-powered monitoring product.

        Target customer:
        {customer_type}

        Solution focus:
        {solution}

        Starter repository:
        {repo_url(item["repo"])}

        Build goal:
        Create a branded monitoring portal or app for installers, water-system integrators,
        utility IT teams, small communal utilities, private customers, farms, buildings, or
        industrial sites that need metering, alerts, and operational visibility.

        ThingsLog API rules:
        - Keep ThingsLog usernames, passwords, and API tokens server-side.
        - Use the ThingsLog login flow to obtain a short-lived Bearer token.
        - Use the API token endpoint only from trusted backend code when a longer-lived token is required.
        - Never commit .env files, real tokens, customer device IDs, or customer measurements.
        - Add "Powered by ThingsLog" with a link to https://thingslog.com in the app footer or about page.

        Domain context:
        - Water deployments can use popular water meter brands connected through LoRa, NB-IoT, or wireless M-Bus.
        - ThingsLog can also work with Modbus devices and analog 4-20 mA or 0-3 V sensors.
        - Build for real operational workflows: consumption trends, alarms, pressure/level/flow views,
          leak detection, NRW reduction, pump station checks, tank monitoring, and customer reports.

        Start command:
        {item["start"]}

        First tasks:
        1. Read README.md, AGENTS.md, and CLAUDE.md if present.
        2. Create a .env file from the example values.
        3. Add mock data mode for demos, then wire real ThingsLog API calls through the backend.
        4. Keep the UI practical, clear, and suitable for installers and utility operators.
        """
    ).strip()


def stack_details(stack: str) -> str:
    item = STACKS[stack]
    return f"""
### {stack}

**Repository:** [{item["repo"]}]({repo_url(item["repo"])})

**Best for:** {item["best_for"]}

**Start:** `{item["start"]}`
"""


def repositories_markdown() -> str:
    lines = [
        "## Start from GitHub",
        "",
        "Pick a starter repository, open it with Codex or Claude, and turn it into a branded monitoring product for your customers.",
        "",
    ]
    for repo, description in REPOSITORIES:
        lines.append(f"- **[{repo}]({repo_url(repo)})**: {description}")
    return "\n".join(lines)


with gr.Blocks(
    title="ThingsLog AI Examples",
    css="""
    :root { --tl-blue: #0b5cab; --tl-green: #2f9e44; --tl-ink: #172033; }
    .tl-hero {
      display: grid;
      grid-template-columns: minmax(0, 1.15fr) minmax(280px, 0.85fr);
      gap: 28px;
      align-items: center;
      padding: 22px 0 8px;
    }
    .tl-hero h1 { color: var(--tl-ink); font-size: 42px; line-height: 1.05; margin: 0 0 12px; }
    .tl-hero p { color: #42526b; font-size: 18px; line-height: 1.55; margin: 0; }
    .tl-logo { max-width: 260px; width: 100%; }
    .tl-card img { border-radius: 8px; width: 100%; height: 180px; object-fit: cover; }
    .tl-links a { margin-right: 14px; white-space: nowrap; }
    footer { visibility: hidden; }
    @media (max-width: 820px) {
      .tl-hero { grid-template-columns: 1fr; }
      .tl-hero h1 { font-size: 34px; }
    }
    """,
) as demo:
    gr.HTML(
        """
        <div class="tl-hero">
          <div>
            <h1>Build your monitoring business on ThingsLog</h1>
            <p>
              Starter portals, API examples, and AI prompts for water-meter installers,
              system integrators, utility IT teams, and small communal utilities that want
              their own monitoring, alerting, and reporting apps.
            </p>
            <p class="tl-links" style="margin-top:18px">
              <a href="https://thingslog.com" target="_blank">thingslog.com</a>
              <a href="https://github.com/ThingsLog" target="_blank">GitHub starters</a>
              <a href="https://thingslog.com/thingslog-solutions/intelligent-water/" target="_blank">Water</a>
              <a href="https://thingslog.com/thingslog-solutions/energy-consumption-monitoring/" target="_blank">Energy</a>
              <a href="https://thingslog.com/thingslog-solutions/thingslog-smart-agriculture/" target="_blank">Agriculture</a>
            </p>
          </div>
          <div>
            <img class="tl-logo" src="/file=assets/thingslog-logo.png" alt="ThingsLog logo" />
          </div>
        </div>
        """
    )

    with gr.Row():
        with gr.Column(scale=1):
            gr.Image("assets/solutions/water-monitoring.jpg", label="Water monitoring", show_download_button=False, show_fullscreen_button=False)
        with gr.Column(scale=1):
            gr.Image("assets/solutions/energy-monitoring.png", label="Energy monitoring", show_download_button=False, show_fullscreen_button=False)
        with gr.Column(scale=1):
            gr.Image("assets/solutions/agriculture-monitoring.png", label="Agriculture monitoring", show_download_button=False, show_fullscreen_button=False)

    gr.Markdown(
        """
## Where ThingsLog Fits

ThingsLog helps partners build practical IoT monitoring solutions for water, energy, agriculture,
buildings, and industrial sites. The strongest fit is small and mid-size communal utilities,
municipal operators, installers, and integrators that need fast deployment without building a full
IoT platform from scratch. Larger utilities can also use the examples for pilots, department tools,
and integrations.

For water, ThingsLog supports popular water meter brands connected through LoRa, NB-IoT, or
wireless M-Bus, plus Modbus devices and analog sensors such as 4-20 mA or 0-3 V pressure, level,
flow, and environmental sensors.
        """
    )

    gr.Markdown(repositories_markdown())

    with gr.Row():
        stack = gr.Dropdown(list(STACKS), value="Next.js portal", label="Choose starter")
        agent = gr.Dropdown(["Codex", "Claude"], value="Codex", label="AI agent")

    customer_type = gr.Textbox(
        label="Target customer",
        value="Small communal water utility or local water-system integrator serving private customers and municipalities",
    )
    solution = gr.Textbox(
        label="Monitoring product idea",
        value="Water consumption dashboard with alarms, leak indicators, meter status, customer reporting, and a Powered by ThingsLog footer",
    )

    details = gr.Markdown()
    prompt = gr.Textbox(label="Prompt for your AI agent", lines=22, show_copy_button=True)

    stack.change(stack_details, inputs=stack, outputs=details)
    for field in (stack, customer_type, solution, agent):
        field.change(build_prompt, inputs=[stack, customer_type, solution, agent], outputs=prompt)

    demo.load(stack_details, inputs=stack, outputs=details)
    demo.load(build_prompt, inputs=[stack, customer_type, solution, agent], outputs=prompt)

    gr.Markdown(
        """
## Token Flow

1. Sign in to the ThingsLog IoT portal with a partner or customer account.
2. Exchange credentials for a Bearer token from the ThingsLog login endpoint.
3. For trusted backend services, create a named long-term API token with an expiration period.
4. Store tokens only in backend environment variables or secret managers.
5. Build customer-facing apps through a backend gateway, never by exposing ThingsLog tokens in frontend code.

Read the full guide in the [thingslog-ai-examples token document](https://github.com/ThingsLog/thingslog-ai-examples/blob/main/docs/generate-thingslog-api-token.md).

**Powered by [ThingsLog](https://thingslog.com).**
        """
    )


if __name__ == "__main__":
    demo.launch()