43 | {"schema":"libjg2-1",
44 | "vpath":"/git/",
45 | "avatar":"/git/avatar/",
46 | "alang":"",
47 | "gen_ut":1575217508,
48 | "reponame":"libwebsockets",
49 | "desc":"libwebsockets lightweight C networking library",
50 | "owner": { "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" },"url":"https://libwebsockets.org/repo/libwebsockets",
51 | "f":3,
52 | "items": [
53 | { "schema":"libjg2-1",
54 | "oid":{ "oid": "bca993f7ed08e27083ea76311e5c717363a2760c", "alias": [ "refs/heads/master"]},"tree": [
55 | { "name": "READMEs","mode": "16384", "size":0},
56 | { "name": "cmake","mode": "16384", "size":0},
57 | { "name": "contrib","mode": "16384", "size":0},
58 | { "name": "doc-assets","mode": "16384", "size":0},
59 | { "name": "include","mode": "16384", "size":0},
60 | { "name": "lib","mode": "16384", "size":0},
61 | { "name": "lwsws","mode": "16384", "size":0},
62 | { "name": "minimal-examples","mode": "16384", "size":0},
63 | { "name": "plugin-standalone","mode": "16384", "size":0},
64 | { "name": "plugins","mode": "16384", "size":0},
65 | { "name": "scripts","mode": "16384", "size":0},
66 | { "name": "test-apps","mode": "16384", "size":0},
67 | { "name": "win32port","mode": "16384", "size":0},
68 | { "name": ".gitignore","mode": "33188", "size":724},
69 | { "name": ".mailmap","mode": "33188", "size":103},
70 | { "name": ".travis.yml","mode": "33188", "size":3130},
71 | { "name": "CMakeLists.txt","mode": "33188", "size":89374},
72 | { "name": "Kconfig","mode": "33188", "size":857},
73 | { "name": "LICENSE","mode": "33188", "size":2585},
74 | { "name": "Makefile.projbuild","mode": "33188", "size":54},
75 | { "name": "README.md","mode": "33188", "size":10248},
76 | { "name": "appveyor.yml","mode": "33188", "size":3075},
77 | { "name": "changelog","mode": "33188", "size":42341},
78 | { "name": "component.mk","mode": "33188", "size":1659},
79 | { "name": "libwebsockets.dox","mode": "33188", "size":14433}],"s":{"c":1575217508,"u": 3097}}
80 | ,{"schema":"libjg2-1",
81 | "cid":"68eb63c5e2d96476721a64ac2323fdb9",
82 | "oid":{ "oid": "bca993f7ed08e27083ea76311e5c717363a2760c", "alias": [ "refs/heads/master"]},"blobname": "README.md", "blob": "[](https://travis-ci.org/warmcat/libwebsockets) [](https://ci.appveyor.com/project/lws-team/libwebsockets) [](https://scan.coverity.com/projects/3576) [](https://bestpractices.coreinfrastructure.org/projects/2266) [](https://www.codacy.com/app/lws-team/libwebsockets?utm_source\u003dgithub.com\u0026amp;utm_medium\u003dreferral\u0026amp;utm_content\u003dwarmcat/libwebsockets\u0026amp;utm_campaign\u003dBadge_Grade) [](https://lgtm.com/projects/g/warmcat/libwebsockets/alerts/) [](https://lgtm.com/projects/g/warmcat/libwebsockets/context:cpp) [](https://lgtm.com/projects/g/warmcat/libwebsockets/context:javascript)\n\n# Libwebsockets\n\nLibwebsockets is a simple-to-use, pure C library providing client and server\nfor **http/1**, **http/2**, **websockets** and other protocols in a security-minded,\nlightweight, configurable, scalable and flexible way. It's easy to build and\ncross-build via cmake and is suitable for tasks from embedded RTOS through mass\ncloud serving.\n\n[50 minimal examples](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples) for\nvarious scenarios, CC0-licensed (public domain) for cut-and-paste, allow you to get started quickly.\n\n\n\nNews\n----\n\n## `lws_system`: DHCP client\n\nDHCP client is now another network service that can be integrated into lws, with\n`LWS_WITH_SYS_DHCP_CLIENT` at CMake. When enabled, the `lws_system` state\nis held at `DHCP` until at least one registered network interface acquires a\nusable set of DHCP information including ip, subnet mask, router / gateway\naddress and at least one DNS server.\n\nSee the [api-test-dhcp](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/api-tests/api-test-dhcpc) Minimal Example for how to use.\n\n## UDP integration with `lws_retry`\n\nUDP support in lws has new helper that allow `lws_retry` to be applied for retry,\nand the ability to synthesize rx and tx udp packetloss systemwide to confirm\nretry strategies. Since multiple transactions may be in flight on one UDP\nsocket, the support relies on an `lws_sul` in the transaction object to manage\nthe transaction retries individually.\n\nSee `READMEs/README.udp.md` for details.\n\n## `lws_system`: system state and notification handlers\n\nLws now has the concept of systemwide state held in the context... this is to\nmanage that there may be multiple steps that need the network before it's possible\nfor the user code to operate normally. The steps defined are\n\n`CONTEXT_CREATED`, `INITIALIZED`, `IFACE_COLDPLUG`, `DHCP`, `TIME_VALID`, `POLICY_VALID`,\n`REGISTERED`, `AUTH1`, `AUTH2`, `OPERATIONAL` and `POLICY_INVALID`. OPERATIONAL is the\nstate where user code can run normally.\n\nUser and other parts of lws can hook notifier callbacks to receive and be able to\nveto system state changes, either definitively or because they have been triggered\nto perform a step asynchronously and will move the state on themselves when it\ncompletes.\n\nBy default just after context creation, lws attempts to move straight to OPERATIONAL.\nIf no notifier interecepts it, it will succeed to do that and operate in a\nbackwards-compatible way. Enabling various features like lws ntpclient also enable\nnotifiers that hold progress at the related state until their operation completes\nsuccessfully, eg, not able to enter `TIME_VALID` until ntpclient has the time.\n\nSee `READMEs/README.lws_system.md` for details.\n\n## `lws_system`: HAL ops struct\n\nLws allows you to define a standardized ops struct at context creation time so your\nuser code can get various information like device serial number without embedding\nsystem-specific code throughout the user code. It can also perform some generic\nfunctions like requesting a device reboot.\n\nSee `READMEs/README.lws_system.md` for details.\n\n## `lws_system`: ntpclient\n\nOptional lws system service enabled by cmake `-DLWS_WITH_SYS_NTPCLIENT` intercepts\nthe `lws_system` `TIME_VALID` state and performs ntpclient to get the date and time\nbefore entering `TIME_VALID`. This allows user code to validate tls certificates\ncorrectly knowing the current date and time by the time it reached OPERATIONAL.\n\n## Connection Validity tracking\n\nLws now allows you to apply a policy for how long a network connection may go\nwithout seeing something on it that confirms it's still valid in the sense of\npassing traffic cohernetly both ways. There's a global policy in the context\nwhich defaults to 5m before it produces a PING if possible, and 5m10 before\nthe connection will be hung up, user code can override this in the context,\nvhost (for server) and client connection info (for client).\n\nAn api `lws_validity_confirmed(wsi)` is provided so user code can indicate\nthat it observed traffic that must mean the connection is passing traffic in\nboth directions to and from the peer. In the absence of these confirmations\nlws will generate PINGs and take PONGs as the indication of validity.\n\n## `lws_system`: Async DNS support\n\nMaster now provides optional Asynchronous (ie, nonblocking) recursive DNS resolving.\nEnable with `-DLWS_WITH_SYS_ASYNC_DNS\u003d1` at cmake. This provides a quite\nsophisticated ipv4 + ipv6 capable resolver that autodetects the dns server on\nseveral platforms and operates a UDP socket to its port 53 to produce and parse DNS\npackets from the event loop. And of course, it's extremely compact.\n\nIt broadly follows the getaddrinfo style api, but instead of creating the results\non the heap for each caller, it caches a single result according to the TTL and\nthen provides refcounted const pointers to the cached result to callers. While\nthere are references on the cached result it can't be reaped.\n\nSee `READMEs/README.async-dns.md` for detailed information on how it works, along\nwith `api-tests/api-test-async-dns` minimal example.\n\n## Detailed Latency\n\nYou can now opt to measure and store us-resolution statistics on effective\nlatencies for client operations, and easily spool them to a file in a\nformat suitable for gnuplot, or handle in your own callback. Enable\n`-DLWS_WITH_DETAILED_LATENCY\u003d1` in cmake to build it into lws.\n\nIf you are concerned about operation latency or potential blocking from\nuser code, or behaviour under load, or latency variability on specific\nplatforms, you can get real numbers on your platform using this.\n\nTimings for all aspects of events on connections are recorded, including\nthe time needed for name resolution, setting up the connection, tls\nnegotiation on both client and server sides, and each read and write.\n\nSee `READMEs/README.detailed-latency.md` for how to use it.\n\n## Client connection logic rewrite\n\nLws master now makes much better use of the DNS results for ipv4 and ipv6... it\nwill iterate through them automatically making the best use it can of what's\nprovided and attempting new connections for each potentially usable one in turn\nbefore giving up on the whole client connection attempt.\n\nIf ipv6 is disabled at cmake it can only use A / ipv4 records, but if ipv6 is\nenabled, it tries both; if only ipv6 is enabled it promotes ipv4 to\n::ffff:1.2.3.4 IPv4-in-IPv6 addresses.\n\n## New network helpers for ipv4 and ipv6\n\nAn internal union `lws_sockaddr46` that combines `struct sockaddr_in` and\n`struct sockaddr_in6` is now public, and there are helpers that can parse (using\n`lws_tokenize`) any valid numeric representation for ipv4 and ipv6 either\ninto byte arrays and lengths, or directly to and from `lws_sockaddr46`.\n\n## h2 long poll support\n\nLws now supports the convention that half-closing an h2 http stream may make\nthe stream 'immortal', in terms of not being bound by normal timeouts. For\nthe client side, there's an api that can be applied to the client stream to\nmake it transition to this \u0022read-only\u0022 long poll mode.\n\nSee `READMEs/README.h2-long-poll.md` for full details, including how to test\nit with the minimal examples.\n\n## h1 client parser improvements\n\nH1 is not so simple to parse because the header length is not known until it\nhas been fully parsed. The next header, or http body may be directly coalesced\nwith the header as well. Lws has supported bulk h1 parsing from a buffer for a\nlong time, but on clientside due to interactions with http proxying it had\nbeen stuck parsing the header bytewise out of the tls buffer. In master,\neverything now bulk parses from a buffer and uses a buflist to pass leftovers\nthrough the event loop cleanly.\n\n## `lws_sul` time refactor\n\nJust before v3.2 there was a big refactor about how lws handles time. It now\nexplicitly schedules anything that may happen in the future on a single, sorted\nlinked-list, at us resolution. When entering a poll wait (or returning to an\nevent lib loop) it checks the interval between now and the earliest event on the\nlist to figure out how long to wait if there are no network events. For the\nevent loop case, it sets a native event lib timer to enforce it.\n\nSee `READMEs/README.lws_sul.md` for more details and a handy api where you can\nschedule your own arbitrary callbacks using this system.\n\n## Master is now MIT-licensed\n\nLibwebsockets master is now under the MIT license. See ./LICENSE.\n\n## Support\n\nThis is the libwebsockets C library for lightweight websocket clients and\nservers. For support, visit\n\n https://libwebsockets.org\n\nand consider joining the project mailing list at\n\n https://libwebsockets.org/mailman/listinfo/libwebsockets\n\nYou can get the latest version of the library from git:\n\n- https://libwebsockets.org/git\n\nDoxygen API docs for master: https://libwebsockets.org/lws-api-doc-master/html/index.html\n\n","s":{"c":1575217508,"u": 3592}}
83 | ],"g": 5504,"chitpc": 0,"ehitpc": 0,
84 | "indexed":0
85 | }
86 |
87 |
88 |
5 |
6 | **GUI.py**
7 |
8 | The same script as publisher with option of requests modification.
9 | To be able to run the GUI you need to install pysimplegui.
10 |
11 | **pip3 install pysimplegui**
12 |
13 | Run the scrpit by using the command python3 GUI.py to run the regular generator.
14 | To configure the generator, use the command python3 GUI.py followed by a random argument.
15 | ex:
16 | **python3 GUI.py custom**
17 |
18 |
19 | **subscriber.py**
20 |
21 | Subscriber is a sample of what file that is uses mqtt mosquitto and subscribes to the content publishd by publisher.
22 | It Connects to the MQTT Broker (Mosquitto) and subscribes to the same topic that the publisher is using to publish data.
23 | At every publication the data received is shown.
24 |
25 | **!! This applicative (subscriber.py) is not going to be part of the generator, it is only used for testing purposes !!**
26 |
27 | References:
28 | Steve Cope, Beginners Guide To The Paho MQTT Python Client, http://www.steves-internet-guide.com/into-mqtt-python-client/
29 |
30 |
31 |
--------------------------------------------------------------------------------
/generator/database.py:
--------------------------------------------------------------------------------
1 | import paho.mqtt.client as paho
2 | import pymongo
3 |
4 | myclient = pymongo.MongoClient("mongodb://localhost:27017/")
5 | mydb = myclient["vasttrafik"]
6 |
7 | broker="localhost"
8 | port=1883
9 |
10 | def on_connect(client, userdata, flags, rc):
11 | print("Connected with result code "+str(rc))
12 | client.subscribe("apicaller/data")
13 |
14 | def on_message(client, userdata, msg):
15 | print("Message received:")
16 | print(str(msg.topic) + " " + str(msg.payload.decode()))
17 |
18 | message = msg.payload.decode()
19 | print(message)
20 |
21 | mycol = mydb["datapoints"]
22 | mydict = { "name": "John", "address": "Highway 37" }
23 | x = mycol.insert_one(mydict)
24 |
25 | client = paho.Client()
26 | client.connect(broker,port,60)
27 |
28 | client.on_connect = on_connect
29 | client.on_message = on_message
30 |
31 | client.loop_forever()
--------------------------------------------------------------------------------
/generator/publisher.py:
--------------------------------------------------------------------------------
1 | import paho.mqtt.client as paho
2 | from faker import Faker
3 | import json
4 | import datetime
5 | import time
6 |
7 | def on_publish(client,userdata,result):
8 | print("data published \n")
9 | print("userdata: " + str(userdata))
10 | print("result: " + str(result))
11 | pass
12 |
13 | fake = Faker()
14 |
15 | requests_per_minute = 30
16 |
17 | broker="test.mosquitto.org"
18 | port=1883
19 |
20 | deviceId = fake.pyint(min_value=0, max_value=9999, step=1)
21 |
22 | # the coordinates are generated in the area of gothenburg
23 |
24 | gbLat = 57.710 # latitude of the center of the city of gothenburg
25 | gbLng = 11.973 # longitude of the center of the city of gothenburg
26 |
27 | # RUSH HOURS 7 to 9, 15 to 18
28 | client = paho.Client()
29 | client.on_publish = on_publish
30 | client.connect(broker,port,60)
31 |
32 | currentTime = datetime.datetime.now()
33 |
34 | startTime = datetime.datetime.now()
35 | prevTime = 0
36 |
37 | i=0
38 |
39 | while True:
40 | if int((datetime.datetime.now() - startTime).total_seconds()) > prevTime:
41 | prevTime = int((datetime.datetime.now() - startTime).total_seconds())
42 | currentTime += datetime.timedelta(minutes=1)
43 |
44 | requestId = i
45 | i+=1
46 |
47 | epoch = time.time()
48 |
49 | latA = str(fake.coordinate(center=gbLat, radius=0.10))
50 | lngA = str(fake.coordinate(center=gbLng, radius=0.15))
51 | latB = str(fake.coordinate(center=gbLat, radius=0.10))
52 | lngB = str(fake.coordinate(center=gbLng, radius=0.15))
53 |
54 | ts = currentTime.strftime("%Y-%m-%d %H:%M")
55 |
56 | if fake.pyint(min_value=0, max_value=1, step=1) == 0:
57 | purpose = "work"
58 | else:
59 | purpose = "leisure"
60 |
61 | json_data = {
62 | 'deviceId': deviceId,
63 | 'requestId': requestId,
64 | 'origin':{
65 | 'latitude': latA,
66 | 'longitude': lngA
67 | },
68 | 'destination':{
69 | 'latitude': latB,
70 | 'longitude': lngB
71 | },
72 | 'timeOfDeparture': ts,
73 | 'purpose': purpose,
74 | 'issuance' : epoch
75 | }
76 |
77 | print(json.dumps(json_data, indent=4, sort_keys=True))
78 |
79 | time.sleep(60/requests_per_minute)
80 | client.publish("external", json.dumps(json_data))
81 |
82 | #hour = currentTime.hour
83 | #if (hour >= 7 and hour < 9) or (hour >= 15 and hour < 18):
84 | # sleepTime = 0.1
85 | #else:
86 | # sleepTime = 1
87 |
88 | #time.sleep(sleepTime)
89 |
90 | client.disconnect()
91 |
--------------------------------------------------------------------------------
/generator/subscriber.py:
--------------------------------------------------------------------------------
1 | import paho.mqtt.client as paho
2 | broker="localhost"
3 | port=1883
4 |
5 | def on_connect(client, userdata, flags, rc):
6 | print("Connected with result code "+str(rc))
7 | client.subscribe("generator/points")
8 |
9 | def on_message(client, userdata, msg):
10 | print("Message received:")
11 | print(str(msg.topic) + " " + str(msg.payload.decode()))
12 |
13 | message = msg.payload.decode()
14 | divided = message.split(",")
15 | print(divided[0] + " " + divided[1] + " " + divided[2] + " " + divided[3])
16 | print(divided[4])
17 |
18 | client = paho.Client()
19 | client.connect(broker,port,60)
20 |
21 | client.on_connect = on_connect
22 | client.on_message = on_message
23 |
24 | client.loop_forever()
--------------------------------------------------------------------------------