Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pi.hub
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
iot
pi.hub
Commits
3daa756b
Commit
3daa756b
authored
Jul 07, 2017
by
Martin Kotula
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use static mqtt client in hub. Getting queue is empty excpetion
parent
4580fe0b
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
7 deletions
+14
-7
Pi.Hub.Api/Controllers/StatusController.cs
+12
-4
Pi.Hub.Api/Program.cs
+1
-2
Pi.Hub.Api/appsettings.json
+1
-1
No files found.
Pi.Hub.Api/Controllers/StatusController.cs
View file @
3daa756b
...
@@ -13,6 +13,14 @@ namespace Pi.Hub.Api.Controllers
...
@@ -13,6 +13,14 @@ namespace Pi.Hub.Api.Controllers
[
Route
(
"api/[controller]"
)]
[
Route
(
"api/[controller]"
)]
public
class
StatusController
:
Controller
public
class
StatusController
:
Controller
{
{
static
StatusController
(){
Client
=
new
MqttClient
(
"test.mosquitto.org"
);
Client
.
Connect
(
Guid
.
NewGuid
().
ToString
());
}
static
MqttClient
Client
;
[
HttpGet
]
[
HttpGet
]
[
Route
(
"[action]"
)]
[
Route
(
"[action]"
)]
public
object
Now
()
public
object
Now
()
...
@@ -25,11 +33,11 @@ namespace Pi.Hub.Api.Controllers
...
@@ -25,11 +33,11 @@ namespace Pi.Hub.Api.Controllers
public
object
Write
([
FromBody
]
object
obj
)
public
object
Write
([
FromBody
]
object
obj
)
{
{
string
serialized
=
JsonConvert
.
SerializeObject
(
obj
);
string
serialized
=
JsonConvert
.
SerializeObject
(
obj
);
var
client
=
new
MqttClient
(
"test.mosquitto.org"
);
// var client =
string
topic
=
"e1s/iot.challange"
;
string
topic
=
"e1s/iot.challange"
;
client
.
Connect
(
Guid
.
NewGuid
().
ToString
());
//
client.Connect(Guid.NewGuid().ToString());
client
.
Publish
(
topic
,
Encoding
.
UTF8
.
GetBytes
(
serialized
),
MqttMsgBase
.
QOS_LEVEL_AT_LEAST_ONCE
,
false
);
Client
.
Publish
(
topic
,
Encoding
.
UTF8
.
GetBytes
(
serialized
)
);
client
.
Disconnect
();
//
client.Disconnect();
return
new
return
new
{
{
...
...
Pi.Hub.Api/Program.cs
View file @
3daa756b
...
@@ -29,8 +29,7 @@ namespace Pi.Hub.Api
...
@@ -29,8 +29,7 @@ namespace Pi.Hub.Api
WebHost
WebHost
.
CreateDefaultBuilder
(
args
)
.
CreateDefaultBuilder
(
args
)
.
UseStartup
<
Startup
>()
.
UseStartup
<
Startup
>()
// .UseKestrel(opt => opt.Listen(IPAddress.Parse(configuration["PiHub:Address"]), int.Parse(configuration["PiHub:Port"])))
.
UseKestrel
(
opt
=>
opt
.
Listen
(
IPAddress
.
Parse
(
configuration
[
"PiHub:Address"
]),
int
.
Parse
(
configuration
[
"PiHub:Port"
])))
.
UseKestrel
()
.
Build
();
.
Build
();
}
}
}
}
Pi.Hub.Api/appsettings.json
View file @
3daa756b
{
{
"PiHub"
:
{
"PiHub"
:
{
"Address"
:
"10.0.
200.22
"
,
"Address"
:
"10.0.
100.8
"
,
"Port"
:
5000
"Port"
:
5000
},
},
"Logging"
:
{
"Logging"
:
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment