Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Webhook (odoo18)

Subscribe

Get notified when there's activity on this post

This question has been flagged
configuration
1 Reply
2608 Views
Avatar
Eldi

import time

import json

import logging

from odoo import http

from odoo.http import request

from chirpstack_api import integration

from google.protobuf.json_format import Parse, MessageToDict


_logger = logging.getLogger(__name__)


class ChirpStackWebhook(http.Controller):


def _log(self, msg):

timestamp = time.strftime("%Y-%m-%d %H:%M:%S")

_logger.info(f"[{timestamp}] {msg}")


@http.route('/chirpstack/webhook', type='http', auth='public', methods=['POST'], csrf=False)

def webhook_handler(self, **kwargs):

try:

self._log("\n" + "=" * 50)

self._log(f"Incoming request to: {request.httprequest.path}")

# Log request details

event = request.httprequest.args.get('event', '')

content_type = request.httprequest.content_type.lower()

raw_body = request.httprequest.get_data()


self._log(f"Event type: {event}")

self._log(f"Content-Type: {content_type}")

self._log(f"Body size: {len(raw_body)} bytes")


# Log body content based on content type

if 'application/json' in content_type:

self._log("Payload format: JSON")

self._log(f"Body (truncated): {raw_body[:200].decode('utf-8')}...")

else:

self._log("Payload format: Protobuf (binary)")

self._log(f"Hex preview: {raw_body[:20].hex()}...")


# Dispatch to event-specific handler

if event == "up":

return self.process_uplink(raw_body, content_type)

elif event == "join":

return self.process_join(raw_body, content_type)

else:

self._log(f"Unknown event type: {event}")

return request.make_response(json.dumps({

'status': 'ignored',

'event': event

}), headers=[('Content-Type', 'application/json')])


except Exception as e:

# Log errors in the general handler

self._log(f"ERROR in webhook_handler: {str(e)}")

return request.make_response(json.dumps({

'status': 'error',

'message': str(e)

}), headers=[('Content-Type', 'application/json')], status=500)


def process_uplink(self, body, content_type):

try:

self._log("\nProcessing uplink event...")

self._log(f"Body content: {body[:100]}...")


if 'application/json' in content_type:

body_str = body.decode('utf-8')

uplink = Parse(body_str, integration.UplinkEvent())

data = json.loads(body_str)

else:

uplink = integration.UplinkEvent()

uplink.ParseFromString(body)

data = MessageToDict(uplink)


self._log("\nUPLINK EVENT")

self._log(f"Device EUI: {uplink.device_info.dev_eui}")

self._log(f"Payload (hex): {uplink.data.hex()}")

self._log("Full data:")

_logger.info(json.dumps(data, indent=2))


# Log additional information for debugging

if 'txInfo' in data:

self._log(f"Frequency: {data['txInfo'].get('frequency')} Hz")

self._log(f"DR: {data['txInfo'].get('dr')}")


if 'rxInfo' in data and len(data['rxInfo']) > 0:

rx = data['rxInfo'][0]

self._log(f"Gateway ID: {rx.get('gatewayId')}")

self._log(f"RSSI: {rx.get('rssi')}")

self._log(f"SNR: {rx.get('snr')}")


# Optional: Save to Odoo model

self._log("Saving device data to Odoo...")

device = request.env['lora.device'].sudo().create_or_update_device(data)

self._log(f"Device ID: {device.id if device else 'N/A'}")


return request.make_response(json.dumps({

'status': 'success',

'device_id': device.id if device else None

}), headers=[('Content-Type', 'application/json')])


except Exception as e:

# Log errors specific to uplink processing

self._log(f"Uplink processing error: {str(e)}")

return request.make_response(json.dumps({

'status': 'error',

'message': str(e)

}), headers=[('Content-Type', 'application/json')], status=500)


def process_join(self, body, content_type):

try:

self._log("\nProcessing join event...")

self._log(f"Body content: {body[:100]}...")


if 'application/json' in content_type:

join = Parse(body.decode('utf-8'), integration.JoinEvent())

else:

join = integration.JoinEvent()

join.ParseFromString(body)


self._log("\nJOIN EVENT")

self._log(f"Device EUI: {join.device_info.dev_eui}")

self._log(f"DevAddr: {join.dev_addr}")

self._log(f"Application ID: {join.device_info.application_id}")


return request.make_response(json.dumps({

'status': 'success',

'device_eui': join.device_info.dev_eui

}), headers=[('Content-Type', 'application/json')])


except Exception as e:

# Log errors specific to join processing

self._log(f"Join processing error: {str(e)}")

return request.make_response(json.dumps({

'status': 'error',

'message': str(e)

}), headers=[('Content-Type', 'application/json')], status=500)

im trying to get data in odoo module and updeate them but its not working 

curl -X POST http://192.168.20.45:8069/chirpstack/webhook -H "Content-Type: application/json" -d '{
    "event": "up",
    "deviceInfo": {"deviceName": "Temperature Sensor 1", "devEui": "0004A30B001C0537"},
    "rxInfo": [{"gatewayId": "gateway1", "rssi": -75, "snr": 10}],
    "txInfo": {"frequency": 868100000, "dr": 5},
    "data": "AQIDBA==",
    "object": {"volume": 100.5, "tempInlet": 22.5, "tempOutlet": 19.0, "heatingEnergy": 150.0, "coolingEnergy": 120.0},
    "time": "2025-04-17T12:00:00Z"
}'
<!doctype html>
<html lang=en>
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.</p>

0
Avatar
Discard
Eldi
Author

this is the JSON that should we accept and save the data to odoo and show then in our view :

{
    "deduplicationId": "d7ef9334-9455-4762-a8fe-6d67a21e81e0",
    "time": "2025-02-16T13:57:46.037091+00:00",
    "deviceInfo": {
        "tenantId": "52f14cd4-c6f1-4fbd-8f87-4025e1d49242",
        "tenantName": "ChirpStack",
        "applicationId": "6dcf61a7-e201-4128-b562-773eefbe40fc",
        "applicationName": "odoo-lora",
        "deviceProfileId": "d5152431-acb8-4de3-b4b3-784410f765ed",
        "deviceProfileName": "device-01",
        "deviceName": "flow-meter-001",
        "devEui": "04b6488910907499",
        "deviceClassEnabled": "CLASS_A",
        "tags": {}
    },
    "devAddr": "0014b276",
    "adr": false,
    "dr": 0,
    "fCnt": 262,
    "fPort": 1,
    "confirmed": false,
    "data": "ARsAAAAAAAAA0lIDABaREwA=",
    "object": {
        "bytes": 17,
        "tempInlet": 10.8,
        "heatingEnergy": 27,
        "coolingEnergy": 0,
        "tempOutlet": 27.5,
        "emptyTube": false,
        "type": 1,
        "subtype": 0,
        "deviceDefect": false,
        "packetType": "SP01",
        "diagnosticIntervalSetup": 0,
        "deviceStatusBits": 0,
        "volume": 217.81
    },
    "rxInfo": [
        {
            "gatewayId": "41374e4b83434a36",
            "uplinkId": 10241,
            "gwTime": "2025-02-16T13:57:46.037091+00:00",
            "rssi": -44,
            "snr": 11.25,
            "channel": 6,
            "location": {},
            "context": "EBzJLA==",
            "crcStatus": "CRC_OK"
        }
    ],
    "txInfo": {
        "frequency": 867700000,
        "modulation": {
            "lora": {
                "bandwidth": 125000,
                "spreadingFactor": 12,
                "codeRate": "CR_4_5"
            }
        }
    },
    "regionConfigId": "eu868"
}
Christoph Farnleitner

Since you explicitly stated 192.168.20.45:8069, and not 127.0.0.1: Is your Odoo instance actually accessible from other systems within the network? Is the controller working locally, i.e. POST'ing to http://127.0.0.1:8069/chirpstack/webhook from the machine where Odoo is actually running on?
Most likely you have multiple database available to that server. If http://192.168.20.45:8069/web/database/manager returns more than one database to select from, this is your issue.

Avatar
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

Hi,

Please refer to the following links:

1. https://www.cybrosys.com/blog/how-to-use-odoo-18-webhooks-to-connect-external-systems

2. https://www.odoo.com/documentation/18.0/applications/studio/automated_actions/webhooks.html


Hope it helps.

0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
Como ligar do celular para a LATAM?
configuration
Avatar
0
Dec 25
2
¿Cómo puedo hablar con una persona de Vueling?
configuration
Avatar
0
Dec 25
3
how to add landed cost per product, such as adding Customs Tariffs fee on product and other products don't have Customs Tariffs??
configuration
Avatar
0
Dec 25
45
Installation Odoo 17 Community
configuration
Avatar
Avatar
1
Nov 25
1346
Multiple trading names under one legal entity
configuration
Avatar
0
Nov 25
45
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now